json - Geografical center of region in Google Map API -
i'm trying geografical center of region called "středočeský kraj" in json format http://maps.googleapis.com/maps/api/geocode/json?address=st%c5%99edo%c4%8desk%c3%bd%20kraj&sensor=false gives me incorrect result. gives me "lat" : 49.8782223, "lng" : 14.9362955, correct https://www.google.cz/maps/place/st%c5%99edo%c4%8desk%c3%bd+kraj/@50.060218,14.4659312,9z/data=!3m1!4b1!4m2!3m1!1s0x470b939c0e8ff2a3:0x100af0f6614a830 (50.060218,14.4659312) how possible, json return incorrect data?
thanks.
the data returned api isn't incorrect, it's not documented returned location area center of area.
take @ http://gmaps-samples-v3.googlecode.com/svn/trunk/geocoder/v3-geocoder-tool.html#q%3dst%u0159edo%u010desk%fd%20kraj . you'll see there blue rectangle marks bounds of area.
to center of bounds instead of marker-location calculate based on bounds:
new google.maps.latlngbounds(new google.maps.latlng(49.501336,13.397336), new google.maps.latlng(50.619099,15.534525)) .getcenter();//returns 50.060217, 14.465930(prague)
as seems request address on serverside, may calculate center without using javascript-api:
lat:(bounds.southwest.lat+bounds.northeast.lat)/2 lng:(bounds.southwest.lng+bounds.northeast.lng)/2
note: result mathematical center, not geographic center(the returned latitude differ), use-case should sufficient. calculate geographical center use haversine-formula
Comments
Post a Comment