Click here to Skip to main content
15,883,876 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

Get location from latitude and longitude using the below code in javascript
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.

C#
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
Updated 21-Jan-13 3:07am
v3

1 solution

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:

C#
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):

C#
IGeoCoder geoCoder = new YahooGeoCoder("my-app-ID");
Address[] addresses = geoCoder.ReverseGeoCode(38.8976777, -77.036517);


Cheers,
Edo
 
Share this answer
 
Comments
hasbina 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900