{"id":74,"date":"2015-04-03T21:46:02","date_gmt":"2015-04-03T21:46:02","guid":{"rendered":"http:\/\/www.clientcyde.com\/?p=74"},"modified":"2015-06-09T20:12:17","modified_gmt":"2015-06-09T20:12:17","slug":"convert-latlng-to-point-and-point-to-latlng-in-google-maps-api-v3","status":"publish","type":"post","link":"https:\/\/www.clientcyde.com\/?p=74","title":{"rendered":"Convert LatLng to Point and Point to LatLng in Google Maps API v3"},"content":{"rendered":"<p>Having googled this, I found code to go one direction, but not the other. \u00a0Here&#8217;s both.<\/p>\r\n<pre>function latLngToPoint(latLng) {\r\n var topRight = map.getProjection().fromLatLngToPoint(map.getBounds().getNorthEast());\r\n var bottomLeft = map.getProjection().fromLatLngToPoint(map.getBounds().getSouthWest());\r\n var scale = Math.pow(2, map.getZoom());\r\n var worldPoint = map.getProjection().fromLatLngToPoint(latLng);\r\n return new google.maps.Point((worldPoint.x - bottomLeft.x) * scale, (worldPoint.y - topRight.y) * scale);\r\n}\r\n\r\nfunction PointTolatLng(point) {\r\n var topRight = map.getProjection().fromLatLngToPoint(map.getBounds().getNorthEast());\r\n var bottomLeft = map.getProjection().fromLatLngToPoint(map.getBounds().getSouthWest());\r\n var scale = Math.pow(2, map.getZoom());\r\n return map.getProjection().fromPointToLatLng(new google.maps.Point((point.x \/ scale) + bottomLeft.x, (point.y \/ scale) + topRight.y));\r\n}<\/pre>\r\n","protected":false},"excerpt":{"rendered":"<p>Having googled this, I found code to go one direction, but not the other. \u00a0Here&#8217;s both. function latLngToPoint(latLng) { var topRight = map.getProjection().fromLatLngToPoint(map.getBounds().getNorthEast()); var bottomLeft = map.getProjection().fromLatLngToPoint(map.getBounds().getSouthWest()); var scale = Math.pow(2, map.getZoom()); var worldPoint = map.getProjection().fromLatLngToPoint(latLng); return new google.maps.Point((worldPoint.x &#8211; bottomLeft.x) * scale, (worldPoint.y &#8211; topRight.y) * scale); } function PointTolatLng(point) { var topRight = &hellip; <a href=\"https:\/\/www.clientcyde.com\/?p=74\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Convert LatLng to Point and Point to LatLng in Google Maps API v3<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[],"class_list":["post-74","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/www.clientcyde.com\/index.php?rest_route=\/wp\/v2\/posts\/74","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.clientcyde.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.clientcyde.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.clientcyde.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.clientcyde.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=74"}],"version-history":[{"count":2,"href":"https:\/\/www.clientcyde.com\/index.php?rest_route=\/wp\/v2\/posts\/74\/revisions"}],"predecessor-version":[{"id":99,"href":"https:\/\/www.clientcyde.com\/index.php?rest_route=\/wp\/v2\/posts\/74\/revisions\/99"}],"wp:attachment":[{"href":"https:\/\/www.clientcyde.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=74"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.clientcyde.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=74"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.clientcyde.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=74"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}