简体   繁体   English

如何获取google maps api v3 javascript中的地图的纬度,经度onclick?

[英]how to get latitude, longitude onclick of a map in google maps api v3 javascript?

how to know latitude, longitude on click of a map in google maps api v3. 如何在google maps api v3中点击地图上的纬度,经度。 i have done this in google maps api v2 with this code 我已经使用此代码在google maps api v2中完成了此操作

 GEvent.addListener(map, "click", function(overlay, latlng) {
          if (latlng) {
            marker = new GMarker(latlng, {draggable:true});
            GEvent.addListener(marker, "click", function() {
                //alert("hello");
              var html = "<table>" +
                         "<tr><td>Name:</td> <td><input type='text' id='name'/> </td> </tr>" +
                         "<tr><td>Time:</td> <td><input type='text' id='time'/> </td> </tr>" +
                         "<tr><td>Bus Id:</td> <td><input type='text' id='busId'/> </td> </tr>" +
                         "<tr><td>Device Id:</td> <td><input type='text' id='deviceId'/> </td> </tr>" +
                         "<tr><td></td><td><input type='button' value='Save & Close' onclick='saveData()'/></td></tr>";
              marker.openInfoWindow(html);
            });
            map.addOverlay(marker);
          }
        });

how to do this same thing in v3? 如何在v3中做同样的事情?

i tried this but it didn't work. 我试过这个,但它没有用。

google.maps.event.addListener(map, "click", function(overlay,latlng) {
        if (latlng) {
        marker = new google.maps.Marker(latlng);
           google.maps.event.addListener(marker, "click", function() {
              var html = "<table>" +
                         "<tr><td>Name:</td> <td><input type='text' id='name'/> </td> </tr>" +
                         "<tr><td>Time:</td> <td><input type='text' id='time'/> </td> </tr>" +
                         "<tr><td>Bus Id:</td> <td><input type='text' id='busId'/> </td> </tr>" +
                         "<tr><td>Device Id:</td> <td><input type='text' id='deviceId'/> </td> </tr>" +
                         "<tr><td></td><td><input type='button' value='Save & Close' onclick='saveData()'/></td></tr>";
              marker.openInfoWindow(html);
            });
            map.setMap(marker);

         }
        });

You have to use event argument. 你必须使用事件参数。

google.maps.event.addListener(map, 'click', function(event) {

    marker = new google.maps.Marker({position: event.latLng, map: map});

});

You have to use this. 你必须使用它。

 google.maps.event.addListener(map, 'click', function(event) {
    alert("Latitude: " + event.latLng.lat() + " " + ", longitude: " + event.latLng.lng());
  });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从Google Maps V3 API获取经度和纬度? - How to get latitude and longitude from google maps v3 api? 从谷歌地图v3方向api的结果中获取经度和纬度? - Get Latitude and Longitude from result of google map v3 direction api? 如何获取经度和纬度的谷歌在Javascript地图 - how to get longitude and latitude of google maps in javascript 如何使用Google Maps JavaScript API v3加载地图 - How to use Google Maps JavaScript API v3 to Load Map 用20m x 20m的框包装纬度和经度点(Google Maps API V3) - Wrapping latitude and longitude points with a 20m by 20m box (Google Maps API V3) Google Maps API - 如何在不显示地图的情况下从自动完成获取纬度和经度? - Google Maps API - how to get latitude and longitude from Autocomplete without showing the map? 如何获得与Google Maps URL的纬度和经度值相同的Google Geocoder API几何值(经度和纬度) - How to get the Google Geocoder API geometry values (latitude and longitude) same as Google maps URL latitude and longitude values HERE Maps API for Javascript:如何从当前缩放中获取边界经度和纬度可见 Map - HERE Maps API for Javascript : how to get boundaries longitude and latitude from current zoom Visible Map 如何在Google Maps Geolocation API中获取笔记本电脑(wifi)的纬度和经度? - How get latitude and longitude of laptop (wifi) in Google Maps Geolocation API? 如何使用Google Maps javascript获取搜索结果标记的纬度,经度 - How to get latitude, longitude of search result marker with google maps javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM