Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Hi
 
Get location from latitude and longitude using the below code in javascript
 
function getCountry(latLng) {
    geocoder.geocode( {'latLng': latLng},
      function(results, status) {
        if(status == google.maps.GeocoderStatus.OK) {
          if(results[0]) {
            for(var i = 0; i < results[0].address_components.length; i++) {
              if(results[0].address_components[i].types[0] == "country") {
                alert(results[0].address_components[i].long_name);
              }
            }
          }
          else {
            alert("No results");
          }
        }
        else {
          alert("Status: " + status);
        }
      }
    );
  }
 
 
The below code provide the latitude and longitude from location name.
 
void GoogleGeoCode(string address)
{
    string url = "http://maps.googleapis.com/maps/api/geocode/json?sensor=true&address=";
 
    dynamic googleResults = new Uri(url + address).GetDynamicJsonObject();
    foreach (var result in googleResults.results)
    {
        Console.WriteLine("[" + result.geometry.location.lat + "," + result.geometry.location.lng + "] " + result.formatted_address);
    }
}
 
But, how to get location from server side with c# instead it in client side using
latitude and longitude?
 
Thanks.
Posted 21-Jan-13 1:19am
hasbina1.2K
Edited 21-Jan-13 3:07am
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi Hasbina,
 
https://github.com/chadly/Geocoding.net[^]
 
The API returns latitude/longitude coordinates and normalized address information. This can be used to perform address validation, real time mapping of user-entered addresses, distance calculations, and much more.
 
Simple Example:
 
IGeoCoder geoCoder = new GoogleGeoCoder("my-api-key");
Address[] addresses = geoCoder.GeoCode("123 Main St");
It can also be used to return address information from latitude/longitude coordinates (aka reverse geocoding):
 
IGeoCoder geoCoder = new YahooGeoCoder("my-app-ID");
Address[] addresses = geoCoder.ReverseGeoCode(38.8976777, -77.036517);
 
Cheers,
Edo
  Permalink  
Comments
hasbina at 21-Jan-13 7:58am
   
@Edo
sir, how to add the dependency ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 21 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid