2016-07-29 6 views
0

Ich bin neu in Google Map. Ich benutze diesen Code um Google Maps anzuzeigen.Wie kann ich eine Position in google map bekommen und markieren

<!DOCTYPE html> 
<html> 
<head> 
<script src="http://maps.googleapis.com/maps/api/js"></script> 
<script> 
function initialize() { 
    var mapProp = { 
    center:new google.maps.LatLng(32.39793603710494,51.39232635498047), 
    zoom:5, 
    mapTypeId:google.maps.MapTypeId.ROADMAP 
    }; 
    var map=new google.maps.Map(document.getElementById("googleMap"),mapProp); 
} 
google.maps.event.addDomListener(window, 'load', initialize); 
</script> 
</head> 

<body> 
<div id="googleMap" style="width:500px;height:380px;"></div> 
</body> 

</html> 

Jetzt will ich markieren und Breite und Länge ein Ort, wenn ich darauf klicken, wollte ich geografische Breite und Länge speichern in database.How kann ich das tun?

+0

möglich Duplikat [Cant hinzufügen Marker eigene Fliese Karte] (http://stackoverflow.com/questions/27307110/cant-add-markers-to-custom-tile -map) – geocodezip

+0

mögliches Duplikat von [Wie kann ich eine benutzerdefinierte, teilbare und kollaborative Karte erstellen?] (http://stackoverflow.com/questions/19015842/how-can-i-create-a-custom-shareable-and- colaborative-map) – geocodezip

+0

Siehe [Verwenden von PHP/MySQL mit Google Maps] (https://developers.google.com/maps/articles/phpsqlajax_v3) – geocodezip

Antwort

2

Ich habe meine Antwort gestellt, weil ich keine relevanten ans auf beiden spitz Frage sehe.

var map = new google.maps.Map(document.getElementById('map_canvas'), { 
     zoom: 1, 
     center: new google.maps.LatLng(35.137879, -82.836914), 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }); 

var myMarker = new google.maps.Marker({ 
    position: new google.maps.LatLng(47.651968, 9.478485), 
    draggable: true 
}); 

google.maps.event.addListener(myMarker, 'dragend', function (evt) { 
// from here you can get where point marker user put and get that let long using 
// Lat = evt.latLng.lat().toFixed(3) 
// Lng = evt.latLng.lng().toFixed(3) 
// after this you can do ajax call and save at you server and do what ever you wanted to do ... 

    document.getElementById('current').innerHTML = '<p>Marker dropped: Current Lat: ' + evt.latLng.lat().toFixed(3) + ' Current Lng: ' + evt.latLng.lng().toFixed(3) + '</p>'; 
}); 

google.maps.event.addListener(myMarker, 'dragstart', function (evt) { 
    document.getElementById('current').innerHTML = '<p>Currently dragging marker...</p>'; 
}); 

map.setCenter(myMarker.position); 
myMarker.setMap(map); 

html 

<body> 
    <section> 
     <div id='map_canvas'></div> 
     <div id="current">Nothing yet...</div> 
    </section> 
</body> 

Arbeits Demo: link