How get Map Bounds
adelsamy opened this issue · comments
How get Map Bounds
Please provide more context on your issue in the next 24hrs, thank you!
i want get southWest latitude and southWest longitude for mapView how get it
They are not exposed directly by Google, but you can access them like this: http://stackoverflow.com/questions/27324928/ios-google-maps-get-northeast-and-southwest-lat-long-padded-by-certain-size
and check the idle event afterwards.
now i have function get me this
function getMapBounds(region) {
var b = {};
b.northWest = {}; b.northEast = {};
b.southWest = {}; b.southEast = {};
b.northWest.lat = parseFloat(region.latitude) +
parseFloat(region.latitudeDelta) / 2.0;
b.northWest.lng = parseFloat(region.longitude) -
parseFloat(region.longitudeDelta) / 2.0;
b.southWest.lat = parseFloat(region.latitude) -
parseFloat(region.latitudeDelta) / 2.0;
b.southWest.lng = parseFloat(region.longitude) -
parseFloat(region.longitudeDelta) / 2.0;
b.northEast.lat = parseFloat(region.latitude) +
parseFloat(region.latitudeDelta) / 2.0;
b.northEast.lng = parseFloat(region.longitude) +
parseFloat(region.longitudeDelta) / 2.0;
b.southEast.lat = parseFloat(region.latitude) -
parseFloat(region.latitudeDelta) / 2.0;
b.southEast.lng = parseFloat(region.longitude) +
parseFloat(region.longitudeDelta) / 2.0;
return b;
}
but how can get region.longitudeDelta ?
It required some calculation:
CLLocationDegrees longitudeDelta;
if(bounds.northEast.longitude >= bounds.southWest.longitude) {
//Standard case
centre = CLLocationCoordinate2DMake(
(bounds.southWest.latitude + bounds.northEast.latitude) / 2,
(bounds.southWest.longitude + bounds.northEast.longitude) / 2);
longitudeDelta = bounds.northEast.longitude - bounds.southWest.longitude;
} else {
//Region spans the international dateline
centre = CLLocationCoordinate2DMake(
(bounds.southWest.latitude + bounds.northEast.latitude) / 2,
(bounds.southWest.longitude + bounds.northEast.longitude + 360) / 2);
longitudeDelta = bounds.northEast.longitude + 360
- bounds.southWest.longitude;
See http://stackoverflow.com/questions/15208181/convert-gmsvisibleregion-to-clregion-or-mkcoordinateregion for more details. StackOverflow offers a lot of related threads