Reputation: 63
If you look up "Mississauga" on Google Maps, it returns boundaries that look like this:
What I need are the Southwest and Northeast coordinates of the boundary (the red square in the picture above).
However, when I use the Google Maps API, it returns the following bounds:
"bounds": {
"northeast": {
"lat": 43.737351,
"lng": -79.17856599999999
},
"southwest": {
"lat": 43.4173019,
"lng": -79.8101295
}
},
But when you plug these values into a map plotter, it gives the following area:
Which is ridiculously wrong as it includes almost all of Toronto, rather than just Mississauga.
How can I get the proper boundary coordinates of a city? Am I doing something wrong?
Upvotes: 0
Views: 708
Reputation: 927
There's nothing wrong with the Geocoder nor what you're doing.
This bounds from geocoder is covering just enough.
"bounds": {
"northeast": {
"lat": 43.737351,
"lng": -79.17856599999999
},
"southwest": {
"lat": 43.4173019,
"lng": -79.8101295
}
},
It may seem like the Geocoder extended Mississauga's bounds to Toronto, but that is not the real case.
The bounds are extending up to the part of Lake Ontario that belongs to Mississauga, right below the lake part that belongs to Toronto.
The Mississauga area looks something like this when the lake area is also highlighted: http://jsbin.com/xoxevaw/edit?output (Note: The coordinates used for the poly lines which highlights the lake are just approximate)
Upvotes: 0
Reputation: 161334
You could use a KMZ or KML file that contains the bounds of Mississauga. A search for Mississauga KMZ, returned this link
I edited the file to just contain Mississauga
code snippet:
function initialize() {
var map = new google.maps.Map(document.getElementById("map_canvas"));
var kmlLayer = new google.maps.KmlLayer({
url: "http://www.geocodezip.com/geoxml3_test/kmz/Mississauga.kmz",
map: map
})
}
google.maps.event.addDomListener(window, "load", initialize);
html,
body,
#map_canvas {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map_canvas"></div>
Upvotes: 1