Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
688 views
in Technique[技术] by (71.8m points)

rest - How to find latitude and longitude using C#

I have a WCF service in C#.

In the Service call client sends a city name. I want to convert the city name to latitudes and longitudes and store in Database under demographics.

I am planning to use Google API to implement above functionality.

I have obtained an API key from Google and its of type 'Service account'.

How can I obtain the latitude and longitude using which APIs?

Do I need to install some SDK or any REST Service will do?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You could try the NuGet package GoogleMaps.LocationServices, or just spin of its source code. It uses Google's REST API to get lat/long for a given address and vice versa, without the need for an API key.

You use it like this:

public static void Main()
{
    var address = "Stavanger, Norway";

    var locationService = new GoogleLocationService();
    var point = locationService.GetLatLongFromAddress(address);

    var latitude = point.Latitude;
    var longitude = point.Longitude;

    // Save lat/long values to DB...
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...