【问题标题】:(NaN, NaN) when getting latitude and longitude through GET(NaN, NaN) 通过GET获取经纬度时
【发布时间】:2014-03-15 05:14:59
【问题描述】:

当我尝试从 JavaScript 中的 GET 获取纬度和经度信息时,我收到了 (NaN, NaN)。这是我的代码:

var GET = {};
var params = location.search.substr(1).split("&");
for (var i=0; i < params.length; i++) {
    var par = params[i].split('=');
    GET[par[0]] = par[1];
}

function initialize() {
    var latitude_longitude = new google.maps.LatLng(GET['coordinates']);

    // The basic code to call Google Maps JavaScript API v3 ...
}

我必须以明文形式输入纬度和经度(例如... new google.maps.LatLng(59.328614,13.485847))吗?

提前致谢。

【问题讨论】:

    标签: google-maps-api-3 latitude-longitude


    【解决方案1】:

    LatLng() 有两个参数,所以你需要分割坐标:

    function initialize() {
        var csplit = GET['coordinates'].split(',');
    
        var latitude_longitude = new google.maps.LatLng(csplit[0], csplit[1]);
    
        // The basic code to call Google Maps JavaScript API v3 ...
    }
    

    【讨论】:

      【解决方案2】:

      您能否详细说明,coordinates 中存储了什么?

      您可能必须使用split(','),然后写new google.maps.LatLng(parseFloat(value[0]),parseFloat(value[1]))

      【讨论】:

      • 59.328614,13.485847coordinates
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-19
      • 2012-12-06
      • 2013-04-16
      • 2013-03-23
      • 1970-01-01
      • 2012-07-30
      • 2016-03-25
      相关资源
      最近更新 更多