views:

45

answers:

1

Is it possible to mark the locations in google map dynamically with the location name. The client will provide us with the locations names through the rss feed. We will grab that location with php script (thats not a worry) and then want to mark them in google map.

Say if we got the address: Weston Town Recreation Department 20 Alphabet Ln, Weston, MA (781) then we have to mark it in googel map

I dont know much about how to post this or mark this and show dynamically in the web page as I am newbie to this google map

Please guide me in this issue..

I also want to add some details into the popup which comes when mouse over the mark in google map - please suggest the solution for this too

+1  A: 

You'll want to Geocode your addresses and then use the results[idx].geometry.location to set up a marker. (The google maps geocoding page has an example to get you started.)


Google code added here in case it ever changes / ceases to exist.

var geocoder, map;
function initialize() {
  geocoder = new google.maps.Geocoder();
  var latlng = new google.maps.LatLng(-34.397, 150.644);
  var myOptions = {
    zoom: 8,
    center: latlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }
  map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}

function codeAddress() {
  var address = document.getElementById("address").value;
  geocoder.geocode( { 'address': address}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      map.setCenter(results[0].geometry.location);
      var marker = new google.maps.Marker({
          map: map, 
          position: results[0].geometry.location
      });
    } else {
      alert("Geocode was not successful for the following reason: " + status);
    }
  });
}

<body onload="initialize()">
 <div id="map_canvas" style="width: 320px; height: 480px;"></div>
  <div>
    <input id="address" type="textbox" value="Sydney, NSW">
    <input type="button" value="Encode" onclick="codeAddress()">
  </div>
</body>
Sean Vieira