Answer the question
In order to leave comments, you need to log in
How to make Google Maps API v3 center the map on one of multiple open InfoWindows?
Such a task: the company has two offices, in different cities. And dynamically, when a button is pressed, I want to center on the one I need. The bug (or my curvature) is that if you open two balloons, the map will be centered so that the last open balloon is at the top left.
If one balloon is open, all is well. I thought to do infoWindow.close() and center it, but it does not work, no errors appear in the console.
Here is the code:
function initMaps() {
var KOffLatLng = new google.maps.LatLng(50.4322014,30.514801),
LOffLatLng = new google.maps.LatLng(51.4994914,-0.1331221);
var mapOptions = {
zoom: 17,
center: KOffLatLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('mapCanvas'), mapOptions);
var kyivOffice = new google.maps.Marker({
position: KOffLatLng,
map: map,
title: 'title'
});
var londonOffice = new google.maps.Marker({
position: LOffLatLng,
map: map,
title: 'titile'
});
var infoWindowK = new google.maps.InfoWindow({
content: "holding...",
maxWidth: 400
});
var infoWindowL = new google.maps.InfoWindow({
content: "holding2...",
maxWidth: 400
});
infoWindowK.open(map,kyivOffice);
infoWindowL.open(map,londonOffice);
}
function loadScript() {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://maps.googleapis.com/maps/api/js?key=МОЙКЛЮЧБЛАБЛАБЛА&sensor=false&callback=initMaps";
document.body.appendChild(script);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question