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?
from math import cos, asin, sqrt, pi def distance(lat1, lon1, lat2, lon2): p = pi/180 a = 0.5 - cos((lat2-lat1)*p)/2 + cos(lat1*p) * cos(lat2*p) * (1-cos((lon2-lon1)*p))/2 return 12742 * asin(sqrt(a)) #2*R*asin... And for the sake of completeness: Haversine on Wikipedia.
Format("POINT({0} {1})", longitude, latitude)); var nearbyLocations = (from location in _context. Locations where // (Additional filtering criteria here...) select new { LocationID = location.ID, Address1 = location. Address1, City = location. City, State = location.
The Earth rotates one full turn (360º of longitude) in one day. It therefore turns one degree of longitude in 1/360th of a day, or every four minutes. To calculate your longitude, you therefore simply need to work out the time difference between noon at your location and noon at the Prime Meridian.
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... }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With