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

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

问题描述

我有此链接:

<一个href=\"http://www.google.com/maps?cid=0,0,612446611849848549&f=q&source=embed&hl=en&geo$c$c=&q=%D0%A3%D0%BD%D0%B8%D0%B2%D0%B5%D1%80%D0%B7%D0%B0%D0%BB%D0%BD%D0%B0%20%D0%A1%D0%B0%D0%BB%D0%B0%20&sll=,&&ie=UTF8&hq=&hnear=%D0%A3%D0%BD%D0%B8%D0%B2%D0%B5%D1%80%D0%B7%D0%B0%D0%BB%D0%BD%D0%B0%20%D0%A1%D0%B0%D0%BB%D0%B0%20&ll=,&z=15&iwloc=near\" rel=\"nofollow\">http://www.google.com/maps?cid=0,0,612446611849848549&f=q&source=embed&hl=en&geo$c$c=&q=Универзална+Сала+&sll=,&&ie=UTF8&hq=&hnear=Универзална+Сала+&ll=,&z=15&iwloc=near

我要的是检索精确定位地点的纬度LNG。我已经尝试使用地理编码API:

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

<一个href=\"http://maps.googleapis.com/maps/api/geo$c$c/xml?q=%D0%A3%D0%BD%D0%B8%D0%B2%D0%B5%D1%80%D0%B7%D0%B0%D0%BB%D0%BD%D0%B0%20%D0%A1%D0%B0%D0%BB%D0%B0%20&sensor=false\" rel=\"nofollow\">http://maps.googleapis.com/maps/api/geo$c$c/xml?q=Универзална+Сала+&sensor=false

但我没有得到的结果,因为精确是指一个地方,而不是一个地址。

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

我如何获得精确的纬度基于LNG的链接? (我需要这个通过code,因为我刮网站)

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)

推荐答案

您可以从该链接的响应纬度LNG信息。这个环节的反应会是谷歌地图的HTML文件。位置信息在HTML中的JavaScript code某处写的。你可以找到模式视口:{中心:{纬度:XXX,经度:XXX}}在JavaScript code。比如,我发现您的链接的纬度和经度为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:

codeS在地图中心的信息:

codes for map center information:

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

codeS的标记:

codes for the markers:

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.

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

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