我一直在尝试使用新的 Geolocation API。我也有一个 API 密钥。但不知何故,输出显示为“未找到”。有人可以告诉我错误在哪里吗?
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}]} 未找到未找到
Google Maps Geolocation API 文档的链接: https ://developers.google.com/maps/documentation/business/geolocation/
当我手动创建一个 json 对象并使用“curl”命令在命令提示符下运行它时,输出正确。