繁体   English   中英

Google Map地理编码转换为latlng

[英]Google Map geocode to latlng

我正在尝试从此地址解析中获取标记的纬度和经度。对于你们来说,这似乎真的很简单。 抱歉,我已经尝试了很多类似addListener的方法,但是似乎没有任何效果。 请帮忙 :(

    function codeAddress() {
      var address = document.getElementById("address").value;
      geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        map.setCenter(results[0].geometry.location);
        var marker = new google.maps.Marker({
        map: map,
        position: results[0].geometry.location
        });
      } else {
        alert("Geocode was not successful for the following reason: " + status);
        }
      });
    }

我也与地址解析器有一些问题。 这段代码适用于不包含特殊字符的地址:

var addr="YOUR ADDRES";  
 var geocoder = new google.maps.Geocoder();
     geocoder.geocode({address: addr, region: 'ar'}, function(results, status) {
     if (status == google.maps.GeocoderStatus.OK) {
     var GeoPos=results[0].geometry.location;
                                                 }
                                                                             });

检查地址解析功能中的地区参数。 我正在使用ar ,因为我来自阿根廷。

这是一个代码,当我使用地址解析进行搜索时,我可以使用它在我的网站上显示纬度和经度...虽然它显示在而不是文本框中,但当我考虑它时,实际上更好。

var searchlat = new Number(results[0].geometry.location.lat());
var searchlng = new Number(results[0].geometry.location.lng());
document.getElementById('sethomelat').innerHTML=searchlat.toFixed(8)
document.getElementById('sethomelng').innerHTML=searchlng.toFixed(8)

.toFixed()让我指定要显示的小数位数的确切数量。

希望这可以帮助其他有相同问题的人。 :D

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM