Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google maps Zipcode的纬度和经度?_Google Maps_Latitude Longitude - Fatal编程技术网

Google maps Zipcode的纬度和经度?

Google maps Zipcode的纬度和经度?,google-maps,latitude-longitude,Google Maps,Latitude Longitude,嗨,我正在尝试检索给定邮政编码的纬度和经度 这是我的密码 public ActionResult GoogleMap(string address, string Zip) { string Country = "US"; int CustomerID = Convert.ToInt32(Session["CustomerID"]); string DefaultLocation = PrescriberModel.GetDefaultL

嗨,我正在尝试检索给定邮政编码的纬度和经度

这是我的密码

 public ActionResult GoogleMap(string address, string Zip)
    {
        string Country = "US";
        int CustomerID = Convert.ToInt32(Session["CustomerID"]);
        string DefaultLocation = PrescriberModel.GetDefaultLocation((long)CustomerID).Address.ToString();
        ViewBag.PL = address;
        ViewBag.DF = DefaultLocation;

        string Lat = "";
        string Lon = "";
        string PostUrl = "http://ws.geonames.org/postalCodeSearch?postalcode=" + Zip + "&maxRows=10&country=" + Country;
       // WebRequest webRequest= null;
        WebResponse webResponse = webRequest.GetResponse();
        if (webResponse == null)
        { }
        else
        {
            StreamReader sr = new StreamReader(webResponse.GetResponseStream());
            string Result = sr.ReadToEnd().Trim();
            if (Result != "")
            {
                // Load the response into an XML doc
                XmlDocument xdoc = new XmlDocument();
                xdoc.LoadXml(Result);
                //  Navigate to latitude node
                XmlNodeList name = xdoc.GetElementsByTagName("lat");
                if (name.Count > 0)
                {
                    Lat = name[0].InnerText;
                }
                //  Navigate to longitude node
                name = xdoc.GetElementsByTagName("lng");
                if (name.Count > 0)
                {
                    Lon = name[0].InnerText;
                }
            }
        }

        ViewBag.Lat = Lat;
        ViewBag.Lng = Lon;
        return PartialView("_GoogleMap");
    }
我从你那里得到了这个代码

但是这给我在webRequest.GetResponse()上抛出了一个错误 我注意到,在这个示例中,WebRequest没有被实例化,更何况WebRequest是一个抽象类,它不能被实例化

任何帮助我如何使它的代码工作。
谢谢您的时间。

问题是我/我们看不到您的
webRequest
实例是如何创建的。 这会奏效的

        HttpWebRequest request = (HttpWebRequest) WebRequest.Create("http://ws.geonames.org/postalCodeSearch?postalcode=" + Zip + "&maxRows=10&country=" + Country);
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();