使用 Google 地图 API 进行反向地理编码

发布于 2024-08-29 06:04:43 字数 325 浏览 3 评论 0原文

我找到了用于反向地理编码的代码:

var point = new GLatLng (lat[1],long[1]);
var geocoder = new GClientGeocoder();
geocoder.getLocations (point, function(result) { alert (lat[1]+' '+long[1]+' '+result.address); });

但它弹出警报,说 result.address 是“未定义”。任何想法,可能是什么问题?


编辑:成功了,谢谢。

I have found this code for reverse geocoding:

var point = new GLatLng (lat[1],long[1]);
var geocoder = new GClientGeocoder();
geocoder.getLocations (point, function(result) { alert (lat[1]+' '+long[1]+' '+result.address); });

But it pops the alert, saying that result.address is 'undefined'. Any ideas, what could be the problem?


EDIT: Got it working, thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜还是长夜 2024-09-05 06:04:43

你能包括“纬度”和“经度”的定义吗?另外,“long”是保留关键字,因此这可能是一个拼写错误/错误。

此外,返回的结果(至少以 gmaps v2 json 格式)具有更复杂的结构,并且“result.address”不会有任何内容。当我测试它时,我需要使用以下内容访问其中一个地址:

result.Placemark[0].address

see http://code.google.com/apis/maps/documentation/geocoding/index.html#GeocodingResponses

can you include the definitions of 'lat' and 'long'? also, 'long' is a reserved keyword, so that is likely a typo / bug.

also, the results that come back, at least in gmaps v2 json format, have a more complex structure, and 'result.address' won't have anything. when I tested it out, I needed to access one of the addresses with something like:

result.Placemark[0].address

see http://code.google.com/apis/maps/documentation/geocoding/index.html#GeocodingResponses

一生独一 2024-09-05 06:04:43

由此我只能看出 result 没有被传递给函数或者它不是一个对象。

您需要查看回调函数接收哪些参数。文档是这样说的:

此响应将包含一个状态代码,如果成功,还会包含一个或多个地标对象。

如果您使用 Firebug,您可以通过以下方式查看传递给回调的内容:

var point = new GLatLng (lat[1],long[1]);
var geocoder = new GClientGeocoder();
geocoder.getLocations (point, function(result) { 
    window.console.log(arguments);
    // Here you will see what arguments are passed and
    // decide what to do about them
});

From this I can only tell that result is not being passed to the function or it is not an object.

You need to see what parameters the callback function receives. Here's what the documentation says:

This response will contain a Status code, and if successful, one or more Placemark objects.

If you're using Firebug, you can see what's being passed to the callback this way:

var point = new GLatLng (lat[1],long[1]);
var geocoder = new GClientGeocoder();
geocoder.getLocations (point, function(result) { 
    window.console.log(arguments);
    // Here you will see what arguments are passed and
    // decide what to do about them
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文