Click here to Skip to main content
12,394,971 members (67,737 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#

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") {
          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 = "";
    dynamic googleResults = new Uri(url + address).GetDynamicJsonObject();
    foreach (var result in googleResults.results)
        Console.WriteLine("[" + + "," + 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?

Posted 21-Jan-13 1:19am
Updated 21-Jan-13 3:07am

1 solution

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

Solution 1

Hi Hasbina,[^]

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);

hasbina 21-Jan-13 7:58am
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100