【问题标题】:Google maps place search response sending invalid request back from server谷歌地图地方搜索响应从服务器发回无效请求
【发布时间】:2015-05-03 06:26:30
【问题描述】:

我有一个简单的 c# 脚本,它试图从 google maps place api 获取雷达结果。我从开发者控制台创建了一个密钥(为服务器选项创建它,而不是控制台)用于 google places api。

这是我的 https 字符串

https://maps.googleapis.com/maps/api/place/radarsearch/xml?location=37.778720,-122.441683&radius=8047&key=mykeyfromgoogle"

我收到的 xml 响应消息说

<PlaceSearchResponse>
   <status>INVALID_REQUEST</status>
</PlaceSearchResponse>

这是调用它的简单 c# 脚本以及指向 .Net Fiddle fiddle的链接

class Program
{
    static void Main(string[] args)
    {
        Geocoding.GetCoordinates(null);
    }
}

public class Geocoding
{
    public static GeocoderCoordinates GetCoordinates(string region)
    {
        WebRequest request = WebRequest.Create("https://maps.googleapis.com/maps/api/place/radarsearch/xml?location=37.778720,-122.441683&radius=8047&key=myplaceskey"); //&key=AddYourOwnKeyHere

        using (WebResponse response = request.GetResponse())
        {
            using (Stream stream = response.GetResponseStream())
            {
                XDocument document = XDocument.Load(new StreamReader(stream));

                //XElement longitudeElement = document.Descendants("lng").FirstOrDefault();
                //XElement latitudeElement = document.Descendants("lat").FirstOrDefault();

                //if (longitudeElement != null && latitudeElement != null)
                //{
                //    return new GeocoderCoordinates
                //    {
                //        Longitude = Double.Parse(longitudeElement.Value, CultureInfo.InvariantCulture),
                //        Latitude = Double.Parse(latitudeElement.Value, CultureInfo.InvariantCulture)
                //    };
                //}
            }
        }
        return null;
    }
}

public class GeocoderCoordinates
{
    public double Longitude { get; set; }
    public double Latitude { get; set; }

    public override string ToString()
    {
        return String.Format("{0}, {1}", Latitude, Longitude);
    }
}

【问题讨论】:

  • 那么有什么问题..您是否运行了代码并逐步完成了..您能告诉我们问题是什么..以及您现有代码中出现问题和/或问题的位置.. .?
  • 当我查看脚本中的返回值“document”时,它显示“INVALID_REQUEST”。它没有返回任何结果。请确保您在发布之前先了解并阅读我的主题

标签: c# google-maps google-places-api


【解决方案1】:

来自docs雷达搜索请求必须至少包含关键字、名称或类型之一。

您没有包含任何这些参数。

【讨论】:

  • 哦,我明白了。该文档具有误导性。它在上面显示了必需的参数,但随后它说您必须至少具有一个可选参数。奇怪的措辞。谢谢!
  • 将它们放在正确的位置并不容易,当它们根据需要定义它们时也会产生误导,因为这些参数都不是必需的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-06-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多