I have created a system where users can add their location to a map.
After they save it, I store the location in a database. This works
fine if the position isn't known yet. But what I want is that the
marker is displayed when the map load.
I use this code for the map where the user can edit his location:
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(<? echo $data->lng;?>, <? echo
$data->lat;?
>), 12, G_HYBRID_MAP); // het huidige midden instellen, en het zoom
niveau
var marker;
map.addControl(new GMapTypeControl());
map.addControl(new GLargeMapControl()); // Groot zoom/beweeg
control
map.addControl(new GMapTypeControl()); // Control voor wisselen
van kaarttype
map.enableScrollWheelZoom();
GEvent.addListener(map, 'click', function(overlay, point) {
if (point) {
map.clearOverlays();
map.panTo(point);
marker = new GMarker(point, {draggable: true});
map.addOverlay(marker);
document.getElementById("long").value=point.y;
document.getElementById("lat").value=point.x;
document.getElementById("submit").type='submit';
}
});
GEvent.addListener(marker, "dragstart", function() {
map.closeInfoWindow();
});
GEvent.addListener(marker, "dragend", function(marker) {
point = marker.getLatLng();
document.getElementById("long").value=point.y;
document.getElementById("lat").value=point.x;
document.getElementById("submit").type='submit';
});
}
}
The problem is that there is no marker on the map until you click it.
How can I add a standard marker which users can drag around?
Online example:
http://www.60graden.nl/klanten/waarslaapje/public_advertentie_mapsedit.php?advertentie_id=10
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---