PHP Classes

How can I set center of Map when a marker clicked

Recommend this page to a friend!

      Map Builder  >  All threads  >  How can I set center of Map when a...  >  (Un) Subscribe thread alerts  
Subject:How can I set center of Map when a...
Summary:Set center of map when marker is clicked
Messages:4
Author:kakalot
Date:2017-10-24 08:55:10
 

  1. How can I set center of Map when a...   Reply   Report abuse  
Picture of kakalot kakalot - 2017-10-24 08:55:10
Hello,
I'm building list of markers like ex11.php file. But I have some problems when add another layer above the map and that layer is overwrite infowindow of marker. Now I want to change click function of every marker will set mapcenter to its position.

I was changed
------------------------------------------

google.maps.event.addListener(markers[0], "click", function() {
for (i = 0; i < infos.length; i++) {
if (infos[i] != null) { infos[i].close(); }
}
if (geoInfo != null) { geoInfo.close(); }
infos[0].open(map, markers[0]);
});
------------------------------------------

to
------------------------------------------
google.maps.event.addListener(markers[0], "click", function() {
map.panTo(markers[0].getPosition());
for (i = 0; i < infos.length; i++) {
if (infos[i] != null) { infos[i].close(); }
}
if (geoInfo != null) { geoInfo.close(); }
infos[0].open(map, markers[0]);
});
------------------------------------------

But no luck. Please help me to resolve this problem. Thanks!

  2. Re: How can I set center of Map when a...   Reply   Report abuse  
Picture of Vagharshak Tozalakyan Vagharshak Tozalakyan - 2017-10-27 09:53:15 - In reply to message 1 from kakalot
Check Example 16 which was uploaded a couple of minutes ago.

function mbOnAfterInit(map) {
for (var i = 0; i < markers.length; i++) {
// Some code goes here...
google.maps.event.addListener(markers[i], "click", function() {
map.setCenter(this.getPosition());
});
}
}



  3. Re: How can I set center of Map when a...   Reply   Report abuse  
Picture of kakalot kakalot - 2017-10-30 06:59:36 - In reply to message 2 from Vagharshak Tozalakyan
Thank you for your suport!
But in my case I want to set center of map when click to a link of marker lists, like this

<a href="javascript:openInfoWindow(0)">X-Game 2</a>

Check this picture:
sv1.upsieutoc.com/2017/10/30/map.jp ...

When I clicked a link of the lists, InfoWindow shows but behind other layer. So I want to change function "openInfoWindow()" when click() markers link and set map center to markers's position immediately. in this case is marker(0).

I hope you understand my problem. Thank you so much!

  4. Re: How can I set center of Map when a...   Reply   Report abuse  
Picture of kakalot kakalot - 2017-10-30 07:12:23 - In reply to message 3 from kakalot
Hello,
I've resolved for myself

I change openInfoWindow to

function openInfoWindow(index)
{
for (var i = 0; i < infos.length; i++) {
infos[i].close();
}
infos[index].open(map, markers[index]);
map.setCenter(markers[index].getPosition());
}

Thank you!