I want to load multiple locations from a Json file and then dynamically center the map on them. But the center is previously defined and I don't know how to change it after loading locations.
Here is a part of my code:
function initMap() {
// Create the map.
const map = new google.maps.Map(document.getElementById('map'), {
zoom: 5,
center: {lat: 46.59938747882371, lng: 2.985859957134927}, // center defined here...
});
// Load the stores GeoJSON onto the map.
map.data.loadGeoJson('MY_FILE.json', {idPropertyName: 'storeid'});
// Now my Json is loaded, now how can I dynamically center the map?
// Define the custom marker icons, using the store's "category".
map.data.setStyle((feature) => {
return {
icon: {
url: `img/map-marker.png`,
scaledSize: new google.maps.Size(40, 40),
},
};
});
const apiKey = 'MY_API_KEY';
const infoWindow = new google.maps.InfoWindow();
// .....
}
Thank you for your help. ;-) Seb