Sponser Link

JSON array parsing from Bing map reverse geocoding

Bing is provide reverse geo coding, means you can get location from coordinates. You can fetch exact address or nearby list of POI or any type of entity.

Firstly we will declare the class for parse JSON data.

    public class Point

    {

        public string type { get; set; }

        public List coordinates { get; set; }

    }

    public class Address

    {

        public string adminDistrict { get; set; }

        public string adminDistrict2 { get; set; }

        public string countryRegion { get; set; }

        public string formattedAddress { get; set; }

        public string locality { get; set; }

    }

    public class GeocodePoint

    {

        public string type { get; set; }

        public List coordinates { get; set; }

        public string calculationMethod { get; set; }

        public List usageTypes { get; set; }

    }

    public class Resource

    {

        public string __type { get; set; }

        public string isPrivateResidence { get; set; }

        public List businessesAtLocation { get; set; }

    }

    public class ResourceSet

    {

        public int estimatedTotal { get; set; }

        public List resources { get; set; }

    }

    public class RootObject

    {

        public string authenticationResultCode { get; set; }

        public string brandLogoUri { get; set; }

        public string copyright { get; set; }

        public List resourceSets { get; set; }

        public int statusCode { get; set; }

        public string statusDescription { get; set; }

        public string traceId { get; set; }

    }

    public class BusinessAddress

    {

        public double latitude { get; set; }

        public double longitude { get; set; }

        public string addressLine { get; set; }

        public string locality { get; set; }

        public string countryIso2 { get; set; }

        public string formattedAddress { get; set; }

      

    }

    public class BusinessInfo

    {

        public string entityName { get; set; }

        public string phone { get; set; }

        public string type { get; set; }

    }

    public class BusinessesAtLocation

    {

        public BusinessInfo businessInfo { get; set; }

        public BusinessAddress businessAddress { get; set; }

    }

Find location by point using Bing Maps REST Services

Now we will call Bing map API, you have to generate API key for use Bing API.

 private void JSON_Read()

        {

            var json = new WebClient().DownloadString

      ("http://dev.virtualearth.net/REST/v1/locationrecog/

        25.31192017,55.37876171?key={Your Bing API Key}&output=json");

            var root = JsonConvert.DeserializeObject(json);

          BusinessAddress buss_Add = new BusinessAddress();

            foreach (var rs in root.resourceSets)

            {

                foreach (var r in rs.resources)

                {

                    foreach (var b in r.businessesAtLocation)

                    {

                        buss_Add = b.businessAddress;

                    }

                }

            }

        }

    

You will declare the BusinessAddress class object and data will parse into object. You can read the data from buss_Add object and can used accordingly.