1,105,399 Community Members

javascript function for google map

Member Avatar
momonq1990
Junior Poster in Training
57 posts since Jul 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
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()
    {
    ???????
    }
Member Avatar
jparkton
Newbie Poster
4 posts since Jul 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
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);
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: