我一直在尝试使用新的 Geolocation API。我也有一个 API key 。 但不知何故,输出为“未找到”。 有人可以告诉我错误在哪里吗?
require 'net/http' require 'uri' require 'json' require 'httparty' lac=50039 mnc=86 cid=15471 mcc=404 rssi=-69 cell_towers = [{:cellId => cid, :locationAreaCode => lac, :mobileCountryCode => mcc, :mobileNetworkCode => mnc, :signalStrength => rssi }] param = {:cellTowers => cell_towers} puts param.to_json #puts "https://www.googleapis.com/maps/api/geolocation/v1/geolocate?key=#{api_key}" response = HTTParty.post("https://www.googleapis.com/maps/api/geolocation/v1/geolocate?key=my_key", :body => param.to_json, :header => {"Content-Type" => "application/json"}) puts response temp= response.body puts temp
以上代码给出的输出是:
{"cellTowers":[{"cellId":15471,"locationAreaCode":50039,"mobileCountryCode":404,"mobileNetworkCode":86,"signalStrength":-69}]} Not Found Not Found
Google Maps Geolocation API 文档链接: https://developers.google.com/maps/documentation/business/geolocation/
当我手动创建一个 json 对象并使用“curl”命令在命令提示符下运行它时,输出是正确的。
最佳答案
所以我一直在努力解决这个完全相同的问题,但是在 .Net 中使用了一个简单的 http post...
似乎有关 URL 的 API 文档是错误的。
代替:https://www.googleapis.com/maps/api/geolocation/v1/geolocate?key=API_key
实际上是:https://www.googleapis.com/geolocation/v1/geolocate?key=API_key
希望这对您有所帮助!
关于ruby - 通过 Ruby 实现 Google Maps Geolocation API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13061588/