I wanna set up a way in which users can place a marker on the map to tell their address and i should be able to extract the lat and long and store it in the database.
Is there somekinda plugin which i can modify and use ?
I wanna set up a way in which users can place a marker on the map to tell their address and i should be able to extract the lat and long and store it in the database.
Is there somekinda plugin which i can modify and use ?
Maybe this is what you are looking for:
Im using javascript for this.
here you set a marker from the address.
var address= "denmark Århus";
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert(address + " not found");
} else {
map.setCenter(point, 14);
map.addOverlay(new GMarker(point, markerOptions));
}
}
);
First create a function that a accepts a latlng object. This function will add the info to your database and then add the marker if it was successful.
function addRestaurant( latlng ) {
lat = latlng.lat;
lng = latlng.lng;
//Code to add restaurant
if ( dbase_successful ) {
var marker = new google.maps.Marker({
position: latlng,
title: "Some text"
map: map //make your map global
});
}
}
Then add an event listener on the click event of the map that calls the function you just created. Add this to your map initialize code.
google.maps.event.addListener(map, 'click', function(event) { addRestaurant( event.latlng ) } );
Now when your map is clicked add_restaurant will be called with the latlng of the click event on the map.