How to take 5 km points in all directions of a location, geocoding google api?
Asked Answered
E

1

14

Ok so i have these cords:

55.623151, 8.48215

I would like to see the geo codes 5 km from north, south, east, west from this geo location above^.

How can i do this?

Eluvium answered 22/10, 2011 at 10:33 Comment(2)
What do you mean by geo codes? Lat/lng coordinates?Gettysburg
@Jiri yes that is what i meanEluvium
G
21

If you use Google Maps API v3, then you would proceed as follows:

Include the Geometry library into your Web page for Spherical Computations:

<script type="text/javascript" 
    src="http://maps.googleapis.com/maps/api/js?libraries=geometry&sensor=false"> 
</script>

Then you can compute:

var point = new google.maps.LatLng(55.623151, 8.48215);
var spherical = google.maps.geometry.spherical; 
var north = spherical.computeOffset(point, 5000, 0); 
var west  = spherical.computeOffset(point, 5000, -90); 
var south = spherical.computeOffset(point, 5000, 180); 
var east  = spherical.computeOffset(point, 5000, 90); 

You can check a running version on jsfiddle.

Gettysburg answered 22/10, 2011 at 11:10 Comment(3)
When i try to var north = computeOffset(point, 5000, 0); alert('test:' +north); i get no alert at all? not even test: ...Eluvium
@Karem: the geometry functions need to be qualified. I updated my answer correspondingly.Gettysburg
@Karem: I added a running program. When you have problems with spherical, then use google.maps.geometry.spherical.computeOffset(point, 5000, 0);Gettysburg

© 2022 - 2024 — McMap. All rights reserved.