如何获取 Google Maps 查询字符串的纬度/经度? [英] How to Obtain Lat/Lng of Google Maps Query String?

查看:26
本文介绍了如何获取 Google Maps 查询字符串的纬度/经度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个链接:

http://www.google.com/maps?cid=0,0,612446611849848549&f=q&source=embed&hl=en&geocode=&q=Универзална+Сала+&sll=,&&ie=UTF8&hq=&hnear=Универзална+Сала+&ll=,&z=15&iwloc=near

我想要的是检索精确位置的 Lat Lng.我已经尝试使用地理编码 API:

What I want is to retrieve the Lat Lng of the pinpointed place. I have already tried to use the geocoding API:

http://maps.googleapis.com/maps/api/geocode/xml?q=Универзална+Сала+&sensor=false

但我没有得到任何结果,因为精确定位指的是一个地方而不是地址.

but I am getting no results because the pinpoint refers to a place and not an address.

如何根据链接获取精确定位的 Lat Lng?(我需要通过代码来实现,因为我正在抓取一个网站)

How do I obtain the Lat Lng of the pinpoint based on the link? (I need this through code, since I am scraping a site)

推荐答案

您可以从此链接的响应中获取 Lat Lng 信息.此链接的响应将是谷歌地图的 html 文件.位置信息写在 html 内的 javascript 代码中.您可以在 javascript 代码中找到模式viewport:{center:{lat:xxx,lng:xxx}}".例如,我发现您的链接的纬度和经度是 41.999227 和 21.416496,这是地图的中心以及精确定位的位置.或者,如果您有多个结果,您可以找到标记位置:

You can get Lat Lng information from the response for this link. The response of this link would be an html file of google map. The position information is written somewhere in the javascript code inside the html. You can find the pattern "viewport:{center:{lat:xxx,lng:xxx}}" in the javascript code. For instance I found the lat and lng of your link is 41.999227 and 21.416496, which is the center of the map as well as the pinpointed place. Or you can find the markers position if you have more than one result:

地图中心信息代码:

viewport: {
    center: {
       lat: 41.999227,
       lng: 21.416496
    },
    span: {
        lat: 0.006295,
        lng: 0.006295
    },
    zoom: 15,
    mapType: 'm',
    source: 0
},
...

标记代码:

markers: [{
    id: 'A',
    cid: '612446611849848549',
    latlng: {
        lat: 41.999227,
        lng: 21.416496
    },
    ... 

在这种情况下,地图中心和标记具有相同的纬度信息.

In this case, the center of map and the marker has the same latlng information.

这篇关于如何获取 Google Maps 查询字符串的纬度/经度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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