Follow by Email

Wednesday, 18 March 2015

How to get lat long from address in C#

We need to install GoogleMaps.LocationServices from the NuGet package. It uses Google's REST API to get lat/long for a given address. Using these you can get latitude and longitude without any need of any API Key.

To install GoogleMaps.LocationServices, either, run the following command in the Package Manger Console.

PM> Install-Package GoogleMaps.LocationServices

Or, search it on Nuget and install it directly

After Install the above package you can use it like this:

Firstly, Add the NameSpace.

using GoogleMaps.LocationServices;

Then use  GoogleLocationService() class to get the latitude and longitude of any given address.

Example:

  /// <summary>
        /// This is to get the lat long from address
        /// </summary>
        public void GetLatLongFromAddress()
        {
            var address = "920 N. Parish Place, Burbank, CA 91506";  
            var locationService = new GoogleLocationService();
            var point = locationService.GetLatLongFromAddress(address);
            var latitude = point.Latitude;
            var longitude = point.Longitude;

        }

Enjoyyy.... :)

4 comments:

Praveen Ranjan said...

thank to all members,,,especially Abhinav Ranjan Sinha. . . very thankful . . .i appreciate your effort to help others

Abhinav Ranjan Sinha said...

Thanks Praveen...

Ahmed Saber said...

Excellent tutorial. Just to the point. Many thanks.

Sagar said...

GetLatLongFromAddress is returning null for an valid address.

Am I missing something ?

Post a Comment


                                                            

 
Design by Abhinav Ranjan Sinha