Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.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_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript 在谷歌地图上放置标记

Javascript 在谷歌地图上放置标记,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,我正试图点击谷歌地图,在div上显示纬度和经度 这是我的js代码: map.instance.addListener('click', function(e) { if (map.geozones.length < 50) { map.placeMarker(e.latLng); $("#geopoint-list").prepend("<br>"); $("#geopoint-list").prepend("(" + map.markerList[

我正试图点击谷歌地图,在div上显示纬度和经度

这是我的js代码:

map.instance.addListener('click', function(e) {
  if (map.geozones.length < 50) {
    map.placeMarker(e.latLng);
    $("#geopoint-list").prepend("<br>");
    $("#geopoint-list").prepend("(" + map.markerList[0].position.lat() + ", " + map.markerList[0].position.lng() + ")");
  }
);
map.instance.addListener('click',函数(e){
如果(map.geozones.length<50){
地图、地点标记(如latLng);
$(“#地质点列表”)。前置(
”; $(“#地质点列表”).prepend(“+map.markerList[0].position.lat()+”,“+map.markerList[0].position.lng()+”); } );
我刚刚意识到它们都共享同一个位置。我想这是因为
addListener
共享“e”事件。它正在显示的位置,但它们都显示与我放置的第一个位置相同

有什么想法吗? 新的在JS这里


谢谢!

我想这是因为你使用了

map.markerList[0].position.lat()
它将始终占据标记列表位置0上的元素。

尝试:

map.instance.addListener('click', function(e) {
  if (map.geozones.length < 50) {
    map.placeMarker(e.latLng);
    $("#geopoint-list").prepend("<br>");
    $("#geopoint-list").prepend("(" + e.latLng.lat() + ", " + e.latLng.lng() + ")");
  }
);
map.instance.addListener('click',函数(e){
如果(map.geozones.length<50){
地图、地点标记(如latLng);
$(“#地质点列表”)。前置(
”; $(“#地质点列表”).prepend(“+e.latLng.lat()+”,“+e.latLng.lng()+”); } );
谢谢你,伙计!你说得对。为了进一步了解,我把那一行改为:e.latLng.lat()+“,“+e.latLng.lng()”。你的答案也是正确的。我刚刚接受了另一行