Google Map V3 User Adding Markers
I need some code that allows users to add their own markers to my map. Does anybody have an example? Thanks! var initialLocation; var siberia = new google.maps.LatLng(60, 105); va
Solution 1:
It's not a hard job:
Set a click event on the map
google.maps.event.addListener(map, 'click', function(event) { placeMarker(event.latLng); });
Place the marker and make an AJAX call to the server to save the location in the database:
function placeMarker(location) { var marker = new google.maps.Marker({ position: location, map: map }); map.setCenter(location); $.ajax({ url: 'myPHP', data: location, succes: function(){ alert('marker was added'); }, error: function(){ alert('marker wasn't added'); marker.setMap(null); } }); }
Solution 2:
Or, use MarkerManager for maps API v3 and rid yourself of any kind of other little mistake you could make implementing this (like moving markers etc)
Post a Comment for "Google Map V3 User Adding Markers"