问题标签 [google-geolocation]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
4661 浏览

google-maps - Geolocation API not working, nor is Google Maps "My Location"

I must be doing something wrong here, but I can't find what... I'm making a page for my company website that, among other things, provides directions to job sites based on the user's current location. To get their location, I'm using the Geolocation API as implemented in Firefox (I was testing with FF9 and now FF10). For the moment I'm testing with the sample code that is in the Wikipedia article:

(copy/paste this into a text editor, save as "whatever.html", and drag the file to the browser to open it)

Very simple code, and it actually worked fine last Thursday, 01/26/12. (I know, I know, people say "It worked yesterday!" when they actually goofed something up, but I swear it really did.) Since then, however, it's been giving me error code 2, "POSITION_UNAVAILABLE". I have tried it with my work computer on my work network, my work and home computers on my home internet connection, and my work computer on a wifi hotspot from my phone, and it gives error code 2 every time.

I thought maybe I'd somehow goofed something up in my browser or my network settings or something (though I couldn't imagine what), so I tried the next test, which everyone should be able to do:

  1. Go to maps.google.com.
  2. Search for "seattle" (or some other location, whatever).
  3. Click the "Get Directions" button.
  4. In the directions boxes on the left, "A" should say "My location" and "B" should say "seattle". (If it doesn't say "My Location" in A, type "m" into the box, and the auto-populating dropdown will usually have "My Location" as the first option.)
  5. Click the "GET DIRECTIONS" button.
  6. Firefox should pop up a message saying maps.google.com wants to know your location. Click "Share Location".
  7. After a couple seconds, it should either show you directions from somewhere (wherever it thinks your server is) to Seattle, or the "A" box should go blank and it'll say "Could not find your location" or similar toward the top of the map.

And here's the weird thing: I have never yet gotten this to work on any computer. My work computer (on both FF10 and Chrome), my coworkers' computers, my home computer, and my GF's work computer all do the same thing; none can find the location.

So my question is: Is the location API down or something, or am I screwing something up? I haven't been able to find any indications online of an API outage, and it seems like an outage is very unlikely, but if so, why does it not work on any computer I've tried it on? Can anyone else duplicate these findings or know what I'm doing wrong?

Thanks!

0 投票
0 回答
3963 浏览

php - 如何在 PHP Google api 中获取访问者位置

我一直在使用一些 ip location finder,但它令人毛骨悚然。它不仅仅找到有限的位置。

然后我在一些网站上找到了这个谷歌 api 代码,它可以找到你的位置,我猜它可以在全球范围内使用。

现在的问题是,代码使用 JavaScript 而我想要的是 php。这是代码:

我想传递google.loader.ClientLocation.address.city给我的 PHP 代码。

否则,如果您熟悉对 PHP 或 xml 执行相同操作的其他 Google API。

0 投票
1 回答
743 浏览

geolocation - 我可以缓存对 Google geolocation api 的请求并建立 LBS 吗?

google GeoLocation API 在中国不稳定,大约 30% 的请求返回“无法连接到服务器”。

我打算建立一个基于谷歌GeoLoaction API的中间LBS,IE缓存用户的请求并将请求传输给谷歌,同时将结果缓存到我们的服务器。

然后下次用户请求时,如果找到匹配的请求,我可以从我的服务器返回结果或将请求传输到谷歌,从而节省资金并提高访问率。

有没有更好的解决方案?这样做有什么问题吗?

0 投票
1 回答
829 浏览

geolocation - 为什么不同的请求使用google geolocation api返回相同的地理位置

我向 google geolocation api 发送了两个请求:https://www.googleapis.com/geolocation/v1/geolocate?key=[mykey]

第一个请求:

{"Carrier":"T-Mobile","CellTowers":[{"Age":0,"CellId":"39627456","LocationAreaCode":"40495","MobileCountryCode":"310","MobileNetworkCode" :"260","SignalStrength":-95,"timingAdvance":0}],"HomeMobileCountryCode":"310","HomeMobileNetworkCode":"260","RadioType":"gsm"}

第二个要求:

{"Carrier":"T-Mobile","CellTowers":[{"Age":0,"CellId":"4912","LocationAreaCode":"20516","MobileCountryCode":"460","MobileNetworkCode" :"00","SignalStrength":-60,"timingAdvance":55555}],"HomeMobileCountryCode":"460","HomeMobileNetworkCode":"00","RadioType":"gsm"}

奇怪的是它们都返回相同的地理位置

{“位置”:{“纬度”:39.90403,“lng”:116.407526},“准确度”:18000.0}

有谁知道为什么会这样?是谷歌地理定位数据库的错误吗?我怎样才能获得(大量真实的)测试数据?

0 投票
1 回答
119 浏览

google-maps - 从我自己的系统在谷歌地图中放置自定义标记

我正在开发一个系统,用户将在其中输入有关特定地点的一些信息,例如图像、描述和地理位置,以便我可以获取信息并创建报告。

我想做的是从我的系统中获取这些信息,特别是地理位置并将标记插入到我的谷歌帐户(我的位置)的自定义地图中。我知道可以在我的系统内显示带有标记的自定义地图,但我不想这样做。现在我得到了地理位置然后我去我的谷歌帐户并手动添加一个带有地图信息的标记(https://maps.google.com.br/maps/ms?msid=205818408978727034882.0004e516df27df16c97a2&msa=0&ll=-5.871843, -35.138741&spn=0.318981,0.528374 )。

我不知道我的问题是否清楚,但事实上我想从我的系统中检索这些信息,然后自动插入到我的谷歌帐户中,以便在一些准备会议中显示这张地图。

先谢谢了,期待解答!!

0 投票
0 回答
212 浏览

google-maps - 无法使用 Google 地理编码查找百慕大市和县

0 投票
1 回答
1263 浏览

google-geolocation - Google GeoLocation API 为同一个 wifi 接入点返回不同的结果

我们正在使用 Google 的地理定位 API 来获取 wifi 接入点的 latlong。我们看到了不一致的结果。Google 的 API 在不同的盒子上返回不同的 latlong。当我在我的开发盒上进行测试时,我得到了指向美国某个位置的 latlong。当我在 amazon ec2 盒子上进行测试时,我得到了指向日本某个位置的 latlong。其他人对 Google 的 GeoLocation API 有过同样的经历吗?
下面是来自两个主机的代码和响应字符串。两个主机上的 JDK 和 JSON jar 版本相同。

}

输入 JSON 字符串

{"wifiAccessPoints":[{"signalStrength":60,"macAddress":"6c:f3:7f:4b:37:74"}, {"signalStrength":60,"macAddress":"6c:f3:7f: 4b:37:75"}]}

亚马逊 ec2 主机上的响应 { "location": { "lat": 40.603124, "lng": 140.463922 }, "accuracy": 122000.0 }

对我的开发框的响应(Windows 7)

{“位置”:{“纬度”:37.593392,“lng”:-122.04383},“准确度”:22000.0}

0 投票
1 回答
1500 浏览

google-maps-api-3 - 来自 Amazon EC2 的地理定位请求

我正在部署一个向 Google Maps Geolocation API 发出请求的应用程序。我的请求从我的工作站顺利通过。但是每次我从亚马逊云中的服务器运行它时都会收到 400 Bad Request 错误。

下面是我要测试的示例 curl 请求。使用中的 API 允许使用任何 IP。

以下是错误结果的示例

0 投票
1 回答
1783 浏览

javascript - 获取用户城市的最佳方式是什么?

我知道这看起来像是一个重复的问题,但我的问题略有不同,并且已经发布的任何内容都没有帮助我。

我需要检测用户所在的城市。我目前只是使用一些第三方 API 将用户的 IP 编码为城市名称。但这确实不准确(考虑我的国家尼泊尔,几乎所有地方都显示为首都)。

我尝试使用 HTML5 的地理位置 API,但这只是给了我用户的地理坐标。我尝试使用 Google 的地理编码 API,但没有得到一致的结果格式(可能是因为不同国家/地区的地址写入方式不同)。我的意思是在生成的 JSON 对象中,对于美国的地址,第五个对象给出了城市名称,而对于英国的地址,它是第四个对象,而印度的地址则是其他对象。

例如,

http://maps.googleapis.com/maps/api/geocode/json?latlng=51.441944,%20-0.945556&sensor=true

对比

http://maps.googleapis.com/maps/api/geocode/json?latlng=42.155101995,-71.10080&sensor=true

这种不一致使我的代码很难从结果 JSON 中解析城市名称。

如何从坐标中获取城市的评论中提出了同样的问题?但没有解决办法。

理想情况下,我希望以某种方式将用户的地理坐标映射到他/她的城市名称(如何?)并仅使用基于 IP 的检测作为后备。但是,我为坐标到名称映射(Google API)找到的唯一解决方案不适用于我的情况。

谢谢!

0 投票
0 回答
204 浏览

android - 移动用户和地理位置

我看到很多网站都有关于获取设备地理位置并将其显示在地图上的教程。

但是,我希望获取用户移动设备的地理位置,然后将其推送到数据库(需要帮助)

然后在一张地图上显示多个用户。

本质上,我正在尝试制作 Uber/sidecar 应用程序的客户端,在那里我可以实时看到不同的汽车位置。

有什么有用的教程吗?