1

hi! good day sir.

how can i add a link <a> to body <body> with a function <onclick=""> that change the center of google map.

HTML
    <a href="" onClick="myFunction()">location 1</a>

FUNCTION
    function myFunction()
    {
    ???????
    }
2
Contributors
1
Reply
16
Views
3 Years
Discussion Span
Last Post by jparkton
1

You will need to read up on the Google Maps API which can be found here

I believe this is what you will need to do what you mean?

function initialize() {
  var mapOptions = {
    zoom: 4,
    center: new google.maps.LatLng(-25.363882, 131.044922)
  };

  var map = new google.maps.Map(document.getElementById('map-canvas'),
      mapOptions);

  var marker = new google.maps.Marker({
    position: map.getCenter(),
    map: map,
    title: 'Click to zoom'
  });

  google.maps.event.addListener(map, 'center_changed', function() {
    // 3 seconds after the center of the map has changed, pan back to the
    // marker.
    window.setTimeout(function() {
      map.panTo(marker.getPosition());
    }, 3000);
  });

  google.maps.event.addListener(marker, 'click', function() {
    map.setZoom(8);
    map.setCenter(marker.getPosition());
  });
}

google.maps.event.addDomListener(window, 'load', initialize);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.