Google Api没有给出位置 [英] Google Api is not giving location

查看:85
本文介绍了Google Api没有给出位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google API来获取我的项目中的位置.它有时会给出位置,但在大多数情况下不会给出任何位置.从今天开始,它向服务器返回禁止的错误403. 当我在浏览器中点击URL时,它正在提供位置. 我没有为我的API使用任何密钥,这会导致此问题.

I am using google API to get location in my project. It gives location sometimes but most of the time it does not give any location. and from today it is giving server return an error 403 forbidden. When i am hitting the URL in my browser it is giving location. I am not using any key for my API can it cause this issue.

只需添加- 我从api中获取经纬度,然后从google api中获取位置,并将其存储在数据库中.

Just to add- I get the lat and long from my api and then i get the location from google api and stores it in my database.

我在做什么是:-

public static string getGoogleLocationByLogLat(string log, string lat)
{

    try
    {
         if (log == "")
    {
        log = "0.0";
    }
    if (lat == "")
    {
        lat = "0.0";
    }

    XmlTextReader xReader;
    bool element = false;
    string location = "", time, GL, parentEmail, respDateTime;
    string parentElementName = "";
    string childElementName = "";
    string childElementValue = "", prmryCntact = "";

    string url = "http://maps.google.com/maps/api/geocode/xml?latlng=" + lat + "," + log + "&sensor=true";

    xReader = new XmlTextReader(url);

        while (xReader.Read())
        {

            if (xReader.NodeType == XmlNodeType.Element)
            {

                if (element)
                {
                    parentElementName = parentElementName + childElementName + "<br>";
                }

                element = true;

                childElementName = xReader.Name;

            }

            else if (xReader.NodeType == XmlNodeType.Text | xReader.NodeType == XmlNodeType.CDATA)
            {

                element = false;

                childElementValue = xReader.Value;

                if (childElementName == "formatted_address")
                {
                    location = childElementValue;
                    break;
                }
            }

        }

    if (location.Trim() == "")
    {
        location = "Location not found";
    }

    return location;
    }
    catch (Exception ex)
    {
        return "LOCATION NOT FOUND";
    }
}

推荐答案

添加您的API密钥

&key=yourkey

随着maps api的最新政策更新,我相信这一定是您遇到的情况...

With the latest policy updates to the maps api, i believe this must be the case that you're hitting...

也使用https ...仅允许通过https

Also use https ... It's permitted only over https

这篇关于Google Api没有给出位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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