Add 5 kilo meter in latitude value or longitude value

9,742 views
Skip to first unread message

khaldoon

unread,
Mar 5, 2012, 8:10:41 AM3/5/12
to google-map...@googlegroups.com
Hi,
Is there any way to add 5km distance to latitude, in order to move geographic point to 5 km north or add 5 km to longitude to move 5km east. I want to get the new lat and  lng after adding distance value.
Example:
lat1: 34
lng1: 34
after adding 5km in lat1, new point should be like
new_lat1: 34+5km
new_lng1: 34 (lng1 will remain same as we only added in latitude)

Jeremy Geerdes

unread,
Mar 5, 2012, 8:30:42 AM3/5/12
to google-map...@googlegroups.com
You can do this using Great Circle algorithms.

Here's how to find distance. You would need to solve the equation for lat2.

distance = ((factor * (lat2-lat1)) ^ 2 + (factor * (lng2 - lng1) * cos(lat2 / 57.3)) ^ 2) ^ .5

Note: factor ~ 69.1 for miles ~ 115.1666667 for km

Jeremy R. Geerdes
Generally Cool Guy
Des Moines, IA

For more information or a project quote:

If you're in the Des Moines, IA, area, check out Debra Heights Wesleyan Church!

--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-maps-js-api-v3/-/cB7fUaZ2GEgJ.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.

geoco...@gmail.com

unread,
Mar 5, 2012, 8:33:11 AM3/5/12
to Google Maps JavaScript API v3

Eric Clark

unread,
Sep 20, 2012, 10:30:29 PM9/20/12
to google-map...@googlegroups.com
One important thing is you have to make sure to include the geometry library when you declare your javascript for gmaps


I just did this, my goal was to draw a 1km box around a point. 

ne = google.maps.geometry.spherical.computeOffset(latlng, 500, 0)

latlng is the original latlng object, 500 is the number of meters you want to go, 0 is the number of degrees from North that you want to move in. (0 goes straight up, 90 goes east, 180 south, 270 west)
ne is the resulting latlng 
So to build a square around a point I did:
ne = google.maps.geometry.spherical.computeOffset(latlng, 500, 0) 
ne = google.maps.geometry.spherical.computeOffset(ne, 500, 90)
se = google.maps.geometry.spherical.computeOffset(ne, 1000, 180)
sw = google.maps.geometry.spherical.computeOffset(se, 1000, 270)
nw = google.maps.geometry.spherical.computeOffset(sw, 1000, 0)

var box = new google.maps.Rectangle({
        map:map,
        strokeOpacity:5,
        bounds:new google.maps.LatLngBounds(sw,ne)
        });
Reply all
Reply to author
Forward
0 new messages