I encountered an issue while using GMAP V3. After realizing the need to save map changes in a database, I struggled to find a way to accomplish this task. Before attempting any workarounds, I thought it would be best to gather some ideas first. The community at stackoverflow has always provided me with great insights and solutions for my problems, so I am turning to them once again.
Here's the situation:
I have a script that calculates the elevation of a region, and I have manually added some data to my code as shown below:
var examples = [{
latlngs: [
[-24.116537, -49.358257],
[-24.123348, -49.344267],
[-24.122409, -49.329212],
[-24.116478, -49.306664],
[-24.101001, -49.313376],
[-24.095218, -49.333645]
],
mapType: google.maps.MapTypeId.SATELLITE,
travelMode: 'direct'
}, {
latlngs: [
[-23.991412, -48.894621],
[-23.969345, -48.884353],
[-23.973734, -48.855789],
[-23.996274, -48.860673],
[-24.00085, -48.886786]
]
mapType: google.maps.MapTypeId.SATELLITE,
travelMode: 'direct'
}];
Now let's initialize everything:
function initialize() {
var myLatlng = new google.maps.LatLng(15, 0);
var myOptions = {
zoom: 1,
center: myLatlng,
mapTypeControl: true,
mapTypeId: google.maps.MapTypeId.TERRAIN
}
Next, we have a function to add markers on the map:
// Add a marker and trigger recalculation of the path and elevation
function addMarker(latlng, doQuery) {
if (markers.length < 100) {
var marker = new google.maps.Marker({
position: latlng,
map: map,
draggable: true
})
google.maps.event.addListener(marker, 'dragend', function(e) {
updateElevation();
});
markers.push(marker);
if (doQuery) {
updateElevation();
}
if (markers.length == 100) {
document.getElementById('address').disabled = true;
}
} else {
alert("Apenas 100 pontos podem ser adicionados.");
}
}
So far, everything is functioning correctly. However, I now need to enhance the map by adding a new marker and a save button to allow saving changes to the database. Is there a built-in function within the GMAP API that can facilitate this process?
Another issue I faced is the ability to delete a single marker. Currently, I can only delete all markers at once, but I require the functionality to delete individual markers.
I believe the function addMarker with var marker could potentially be used to store values in a database, but how exactly should I go about implementing this?