views:

26

answers:

1

I want to put a map in a web page where users will be able to put interactive marker (location pins) as many as they want. Now, whenever a marker is placed, I want to store that specified marker's lat, long value to be saved in a database that I have in my server (phpmyadmin).

Trying to get started with Google Map Data API. Have seen lots of examples but could not find any where interactive markers can be placed.

A: 

I'm going to show you how to do it with v3 of the APi

  • Create your map... I'll assume you've got this part down.
  • Add an event listener to the map. This event listener will call a function that will create the marker (in this case add_marker). You can use any event you want, this uses the click event.

google.maps.event.addListener(this.map, 'click', add_marker);

  • Create the function that adds the marker to the db then the map. This will require some AJAX. You use the event.latLng to get the lat/lng

function add_marker( event ) {
    lat = event.latLng.lat;
    lng = event.latLng.lng;
    // ajax code here that posts the lat/lng to the server
    // only call the remaining code to add the marker if it was successful
    var marker = new google.maps.Marker({
        position: event.latLng,
        map: map // put the handle of your map here
    });
}
Galen
Thanks a lot..!
zeb