I have a Google Map on my View.
I wish to save the long and lat of the marker that has just recently been added to the Map.
My ViewModel has a Location object which contains a lat and long.
Does anyone know how I can achieve this?
The following is the code:
function addMarker(location, isdragable) {
marker = new google.maps.Marker({
position: location,
map: _gmMap,
icon: '../../Content/images/pin-red_32.png',
draggable: isdragable
});
$('#mainPlaceHolder_hdnlatlong').val(location.lat() + ',' + location.lng());
markersArray.push(marker);
if (isdragable) {
google.maps.event.addListener(marker, 'dragend', function () {
showLocation(marker.getPosition().lat() + ',' + marker.getPosition().lng(), true);
});
}
$('#spmsg').hide();
}
Assuming that “Save” is supposed to happen on the server, you need to make a request to the server. One way of doing this is to use jQuery’s ajax method:
client-side javascript (replace <…> to fit your need):