转换" [52.43242,4.43242] QUOT;谷歌经纬度 [英] Convert "[52.43242, 4.43242]" to google LatLng

查看:124
本文介绍了转换" [52.43242,4.43242] QUOT;谷歌经纬度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很简单的问题,

i have a very simple question,

我尽量让谷歌的计算和ADRESS含GSP变量之间的距离

I try to let google calculate the distance between an adress and a gsp-variable containing

[53.57532, 10.01534]

我可不是能得到变量 $ {中心} google.maps.LatLng对象

继承人的功能

jQuery(document).ready(function() {
var result = '${center}';
console.log(result);// [53.57532, 10.01534]
var origin = new google.maps.LatLng(55.930385, -3.118425);
var destination = new google.maps.LatLng(result);



var service = new google.maps.DistanceMatrixService();
service.getDistanceMatrix(
{
origins: [origin],
destinations: [destination],
travelMode: google.maps.TravelMode.DRIVING,
avoidHighways: false,
avoidTolls: false
}, callback);

function callback(response, status) {
if (status == google.maps.DistanceMatrixStatus.OK) {
console.log('status OK!');//status OK!
var origins = response.originAddresses;
var destinations = response.destinationAddresses;

for (var i = 0; i < origins.length; i++) {
  var results = response.rows[i].elements;
  for (var j = 0; j < results.length; j++) {
    var element = results[j];
    var distance = element.distance.text;
    var duration = element.duration.text;
    var from = origins[i];
    var to = destinations[j];
    console.log(distance);//Uncaught TypeError: Cannot read property 'text' of undefined 
  }
 }
}
}
});

在源$ C ​​$ C上述谷歌抛出的错误

in the "source code" above google throws error

 Uncaught TypeError: Cannot read property 'text' of undefined 

我trye​​d无谓狗屎了很多,但我只是不明白,

i tryed alot of senseless shit, but i just don get it,

也许有人可以给出一个暗示什么,我做错了什么?
在此先感谢

maybe someone can give a hint what i am doing wrong? thanks in advance

根据意见here's我gmap3也失败了,但我宁愿woulkd这一个投入工作,但我想在这里汇入作业同样的问题,即转换为纬度经度一点儿也不工作。

according to the comments here´s my gmap3 also failing, but i woulkd rather this one to put to work but i guess it´s the same problem here, that converting to lat lon does´nt work

  function getDistance(adress){
var to;
var result = '${center}';



 $("#getdistance").gmap3({
 getdistance:{
  options:{
  origins:adress,
  destinations:result ,
  travelMode: google.maps.TravelMode.DRIVING
},
 callback: function(results, status){
  var html = "";
  if (results){
    for (var i = 0; i < results.rows.length; i++){
      var elements = results.rows[i].elements;
      for(var j=0; j<elements.length; j++){
        switch(elements[j].status){
          case "OK":
            html += elements[j].distance.text + " (" + elements[j].duration.text + ")<br />";
            break;
          case "NOT_FOUND":
            html += "The origin and/or destination of this pairing could not be geocoded<br />";
            break;
          case "ZERO_RESULTS":
            html += "No route could be found between the origin and destination.<br />";
            break;
        }
      }
    }
  } else {
    html = "error";
  }
  console.log('start '+adress);
  console.log('start '+latte);
  console.log('start '+html);
}
}
});

}

在这里i'm解析ADRESS作为一个字符串函数 ADRESS

推荐答案

如何

var result = ${center};
var destination = new google.maps.LatLng(result[0], result[1]);

google.maps.LatLng 不接受一个数组。它接受参数是:数字,数字,布尔

google.maps.LatLng doesn't accept an array. Arguments it accepts are: number, number, bool.

https://developers.google.com/maps/documentation/javascript/参考#经纬度

这篇关于转换&QUOT; [52.43242,4.43242] QUOT;谷歌经纬度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆