none
Geocode error in bing map V8 RRS feed

  • Question

  • Hi,

    We are facing below issue while getting the latitude/longitude in Bingmap V8.

    Unable to connect to the remote server.

    Below is the code that we are using. Is there any other method to get latitude/longitude in Bing map V8.

    internal string restURL = "http://dev.virtualearth.net/REST/v1/Locations";

      //create the geocodeRequest
                    geocodeRequest = new Uri(string.Format(restURL + "?q={0}&key={1}", formattedAddress, _bingMapKey));

                    tracingService.Trace("Geocode request created");

                    // call this function to get the latitude and longitude
                    GetResponse(geocodeRequest, (x) =>
                    {
                        if (x.ResourceSets[0].Resources.Length > 0)
                        {
                            retrieveLocationColl.latitude = (decimal)((BingMapsRESTService.Common.JSON.Location)x.ResourceSets[0].Resources[0]).Point.Coordinates[0];
                            retrieveLocationColl.longitude = (decimal)((BingMapsRESTService.Common.JSON.Location)x.ResourceSets[0].Resources[0]).Point.Coordinates[1];
                        }
                    });


      private void GetResponse(Uri uri, Action<Response> callback)
            {
                WebClient wc = null;
                string functionName = "GetResponse ";


                try
                {
                    if (callback != null)
                    {
                        wc = new MyWebClient();
                        using (var s = wc.OpenRead(uri))
                        {
                            var ser = new DataContractJsonSerializer(typeof(Response));
                            callback(ser.ReadObject(s) as Response);
                        }

                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(functionName + ex.Message);
                }
                finally
                {
                    wc.Dispose();
                }
            }

    Thanks!


    Balasaheb


    Friday, July 21, 2017 3:09 PM

Answers

  • The issue is almost certainly your formattedAddress value. If it contains any special characters such as a # it will break the URL. You need to encode the formatted address value. See the best practices here: https://msdn.microsoft.com/en-us/library/dn894107.aspx

    Since you are using .NET, I highly recommend you use the Bing Maps REST toolkit: https://github.com/Microsoft/BingMapsRESTToolkit There is a niuget package so really easy to add to your project.


    [Blog] [twitter] [LinkedIn]

    Saturday, July 22, 2017 4:26 AM
  • Try passing this query in your application (add your key as appropriate): 

    https://dev.virtualearth.net/REST/v1/Locations?q=California&key=YOUR_BING_MAPS_KEY

    If this query doesn't work, then the issue is more than likely with your proxy service. Looking at the error message you provided earlier, that would make sense. Make sure to whitelist the dev.virtualearth.net domain in your proxy service. Also recommend using https rather than http.


    [Blog] [twitter] [LinkedIn]

    Wednesday, July 26, 2017 4:18 PM

All replies

  • The issue is almost certainly your formattedAddress value. If it contains any special characters such as a # it will break the URL. You need to encode the formatted address value. See the best practices here: https://msdn.microsoft.com/en-us/library/dn894107.aspx

    Since you are using .NET, I highly recommend you use the Bing Maps REST toolkit: https://github.com/Microsoft/BingMapsRESTToolkit There is a niuget package so really easy to add to your project.


    [Blog] [twitter] [LinkedIn]

    Saturday, July 22, 2017 4:26 AM
  • Hi Ricky,

    Thanks for your reply. We have checked with special characters in it still it throws same error.  We run the code from proxy server but we have allow the http://dev.virtualearth.net/REST/v1/Locations. is anything we need to take care in proxy server. Proxy server is the issue or any other issue.

    Waiting for your reply

    Thanks!



    Balasaheb

    Wednesday, July 26, 2017 10:03 AM
  • Try passing this query in your application (add your key as appropriate): 

    https://dev.virtualearth.net/REST/v1/Locations?q=California&key=YOUR_BING_MAPS_KEY

    If this query doesn't work, then the issue is more than likely with your proxy service. Looking at the error message you provided earlier, that would make sense. Make sure to whitelist the dev.virtualearth.net domain in your proxy service. Also recommend using https rather than http.


    [Blog] [twitter] [LinkedIn]

    Wednesday, July 26, 2017 4:18 PM