I'm having troubles centering and zooming on the information in the data layer. I have tried to use the approach suggested here: stackoverflow question: zoom to geojson polygons bounds in Google Maps API v3. I still initially zoom into the same spot that he was, some where in the pacific ocean near baker island. I am loading a GeoJson object from the server and it displays correctly. My code:
function loadMap () {
var m = document.getElementById("googleMap");
var mapProp = {
disableDoubleClickZoom: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(m, mapProp);
map.data.addListener('addfeature', function(e) {
var bounds = new google.maps.LatLngBounds();
processPoints(e.feature.getGeometry(), bounds.extend, bounds);
map.setCenter(bounds.getCenter());
map.fitBounds(bounds);
});
var geoJsonObject = {
type: "FeatureCollection",
features: [
{
type: "Feature",
properties: {},
geometry: {
type: "MultiPolygon",
coordinates: [
[[[-86.80795499999999, 36.146389], [-86.80605800006222, 36.14733499995285], [-86.806471, 36.147928], [-86.80836699994975, 36.14697700000941], [-86.80795499999999, 36.146389]]],
[[[-86.803842, 36.143921999999996], [-86.803761, 36.144005], [-86.80374600001942, 36.1441770000485], [-86.804918, 36.1458], [-86.805436, 36.145536], [-86.80621699999999, 36.146585], [-86.80755499999131, 36.145895000035935], [-86.807208, 36.145385999999995], [-86.806328, 36.144205], [-86.803842, 36.143921999999996]]]
]
}
}
]
};
map.data.addGeoJson(geoJsonObject);
}
function processPoints(geometry, callback, thisArg) {
if(geometry instanceof google.maps.LatLng) {
callback.call(thisArg, geometry);
}
}
Are there any other suggestions?