如何通过javascript从变量中的json谷歌地图api获取地理代码纬度和经度?

如何通过javascript从变量中的json谷歌地图api获取地理代码纬度和经度?,javascript,json,google-maps,google-maps-api-3,Javascript,Json,Google Maps,Google Maps Api 3,JSON地理位置 JS 在IBM Worklight中进行测试 但是我不能得到经纬度 警报(JSON.stringify(jsonLtdLng))//返回完整地址 警报($.getJSON(jsonLtdLng))//返回对象对象 警报($.getJSON(jsonLtdLng.lat))//一无所获 警报($.getJSON(jsonLtdLng.results.geometry.location.lat))//一无所获 警报($.getJSON(jsonLtdLng.results[0].

JSON地理位置

JS

在IBM Worklight中进行测试

但是我不能得到经纬度

警报(JSON.stringify(jsonLtdLng))//返回完整地址

警报($.getJSON(jsonLtdLng))//返回对象对象

警报($.getJSON(jsonLtdLng.lat))//一无所获

警报($.getJSON(jsonLtdLng.results.geometry.location.lat))//一无所获

警报($.getJSON(jsonLtdLng.results[0].geometry.location.lat))//一无所获

警报($.getJSON(jsonLtdLng.results[0].geometry.location.lat())//一无所获

警报(jsonLtdLng.results[0].geometry.location.lat())//不返回任何内容

您对的呼叫不完全正确

试试这个:

$.getJSON(jsonLtdLng, function (data) {
  console.log(data.results[0].geometry.location.lat);
});
你打给我的电话不完全正确

试试这个:

$.getJSON(jsonLtdLng, function (data) {
  console.log(data.results[0].geometry.location.lat);
});

我认为您可以使用
console.log()
alert()
document.write()
只要信息是反序列化的,我就使用
JSON.parse()
进行反序列化,
eval()
是人们以前使用的反序列化意味着恢复json编码的数据,以便Javascript将其用作对象。事实上,如果您使用write.document(someJson),您将看到[object object],这意味着您已经准备好使用所有数据,但是您需要先
JSON.parse()
it
JSON.stringnify()
与您想要做的相反,因为该函数用于序列化数据,然后传输数据,然后接收器需要使用
JSON.parse()
将其反序列化并在Javascript中使用。 我喜欢使用
write.document()
来查看信息,但控制台日志允许您更轻松地查看对象内部的内容。下面是一些代码示例:

// apiData would be the variable with the API information
var externalData = JSON.parse(apiData);

// will output [object object]     
document.write(externalData);

// will output  “     “
document.write('      ');

// will output the latitude
document.write(externalData.results[0].geometry.location.lat);

// will output in the console, you need to type externalData in the console log 
console.log(externalData);

我希望这能有所帮助。

我想你可以使用
console.log()
alert()
document.write()
只要信息是反序列化的,我就使用
JSON.parse()
进行反序列化,
eval()
是人们以前使用的反序列化意味着恢复json编码的数据,以便Javascript将其用作对象。事实上,如果您使用write.document(someJson),您将看到[object object],这意味着您已经准备好使用所有数据,但是您需要先
JSON.parse()
it
JSON.stringnify()
与您想要做的相反,因为该函数用于序列化数据,然后传输数据,然后接收器需要使用
JSON.parse()
将其反序列化并在Javascript中使用。 我喜欢使用
write.document()
来查看信息,但控制台日志允许您更轻松地查看对象内部的内容。下面是一些代码示例:

// apiData would be the variable with the API information
var externalData = JSON.parse(apiData);

// will output [object object]     
document.write(externalData);

// will output  “     “
document.write('      ');

// will output the latitude
document.write(externalData.results[0].geometry.location.lat);

// will output in the console, you need to type externalData in the console log 
console.log(externalData);

我希望这能有所帮助。

感谢它的工作。由alert而不是console.log()测试,但我认为会有一个;语句末尾的分号。console.log(data.results[0].geometry.location.lat);如果是xml格式,该怎么办?是代码吗?Json比XML更容易在javascript中解析,用
Json
更改url
XML
,您将再次获得Json,因为您刚刚询问了Json的知识以及如何获得Json的长度?感谢它的工作。通过alert而不是console.log()进行测试,但我认为会有一个;语句末尾的分号。console.log(data.results[0].geometry.location.lat);如果是xml格式,该怎么办?是代码吗?Json在javascript中比XML更容易解析,用
Json
更改url
XML
,您将再次获得Json,因为您只需询问一下知识以及如何获得Json的长度