Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在谷歌地图中获取并标记位置_Javascript_Php_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript 如何在谷歌地图中获取并标记位置

Javascript 如何在谷歌地图中获取并标记位置,javascript,php,google-maps,google-maps-api-3,Javascript,Php,Google Maps,Google Maps Api 3,我是谷歌地图的新手。 我用这个代码来显示谷歌地图 <!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.39793603

我是谷歌地图的新手。 我用这个代码来显示谷歌地图

<!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>

函数初始化(){
var mapProp={
中心:新google.maps.LatLng(32.39793603710494,51.39232635498047),
缩放:5,
mapTypeId:google.maps.mapTypeId.ROADMAP
};
var map=new google.maps.map(document.getElementById(“googleMap”),mapProp);
}
google.maps.event.addDomListener(窗口“加载”,初始化);

现在我想在点击时标记并获取一个位置的纬度和经度,我想在数据库中保存纬度和经度。我该怎么做?

我已经给出了答案,因为我在这两个问题上都没有看到任何相关的ans

 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>
var map=new google.maps.map(document.getElementById('map_canvas'){
缩放:1,
中心:新google.maps.LatLng(35.137879,-82.836914),
mapTypeId:google.maps.mapTypeId.ROADMAP
});
var myMarker=new google.maps.Marker({
位置:新google.maps.LatLng(47.651968,9.478485),
德拉格布尔:是的
});
google.maps.event.addListener(myMarker,'dragend',function(evt){
//从这里您可以得到用户放置点标记的位置,并使用
//Lat=evt.latLng.Lat().toFixed(3)
//Lng=evt.latLng.Lng().toFixed(3)
//在此之后,您可以在服务器上执行ajax调用和保存,并执行您想做的任何事情。。。
document.getElementById('current').innerHTML='删除的标记:当前Lat:'+evt.latLng.Lat().toFixed(3)+'current Lng:'+evt.latLng.Lng().toFixed(3)+'

'; }); google.maps.event.addListener(myMarker,'dragstart',函数(evt){ document.getElementById('current').innerHTML='当前正在拖动标记…

; }); 地图设置中心(myMarker.position); myMarker.setMap(map); html 还没有。。。

工作演示:

我已经给出了我的答案,因为我在这两个问题上都没有看到任何相关的ans

 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>
var map=new google.maps.map(document.getElementById('map_canvas'){
缩放:1,
中心:新google.maps.LatLng(35.137879,-82.836914),
mapTypeId:google.maps.mapTypeId.ROADMAP
});
var myMarker=new google.maps.Marker({
位置:新google.maps.LatLng(47.651968,9.478485),
德拉格布尔:是的
});
google.maps.event.addListener(myMarker,'dragend',function(evt){
//从这里您可以得到用户放置点标记的位置,并使用
//Lat=evt.latLng.Lat().toFixed(3)
//Lng=evt.latLng.Lng().toFixed(3)
//在此之后,您可以在服务器上执行ajax调用和保存,并执行您想做的任何事情。。。
document.getElementById('current').innerHTML='删除的标记:当前Lat:'+evt.latLng.Lat().toFixed(3)+'current Lng:'+evt.latLng.Lng().toFixed(3)+'

'; }); google.maps.event.addListener(myMarker,'dragstart',函数(evt){ document.getElementById('current').innerHTML='当前正在拖动标记…

; }); 地图设置中心(myMarker.position); myMarker.setMap(map); html 还没有。。。

工作演示:

可能重复的可能重复的可能重复的查看我看到了所有这些链接。我想你的答案与我的问题无关。你的问题不太清楚。可能重复的可能重复的查看我看到了所有这些链接。我想你的答案与我的问题无关。你的问题不太清楚。