I\'m using Google\'s Geocoder to find lat lng coordinates for a given address.
var geocoder = new google.maps.Geocoder();
geocoder.geocode(
{
I have Created Border All Around Uk and check if my Lat and Lng are in the Range. For 3 k addresses I have around 10 up to 20 addresses in US. I just Ignore them(I can do that in my case) I use lat and lng for creating multi markers on static map with auto zoom. I will share my Solution maybe this will be help for someone. Also I'm Happy to hear different Solutions for my case.
private static string ReturnLatandLng(string GeocodeApiKey, string address)
{
string latlng = "";
Geocoder geocoder = new Geocoder(GeocodeApiKey);
var locations = geocoder.Geocode(address);
foreach (var item in locations)
{
double longitude = item.LatLng.Longitude;
double latitude = item.LatLng.Latitude;
double borderSouthLatitude = 49.895878;
double borderNorthLatitude = 62.000000;
double borderWestLongitude = -8.207676;
double borderEastLongitude = 2.000000;
//Check If Geocoded Address is inside of the UK
if (( (borderWestLongitude < longitude) && (longitude < borderEastLongitude) ) && ( (borderSouthLatitude < latitude) && (latitude < borderNorthLatitude) ) )
{
latlng = item.LatLng.ToString();
}
else
{
latlng = "";
Console.WriteLine("GEOCODED ADDRESS IS NOT LOCATED IN UK ADDRESSES LIST. DELETING MARKER FROM MAP.....");
}
}
return latlng;
}