1

I m developing one application in which i m having the address of particular person, now i want to find the location of that person on google map. I want to save the latitude and longitude of that person when i m saving his details. How can i find the latitude and longitude from the address?

In address, i m saving his city, state , country, street, etc.

Thanks, Saloni

Saloni
  • 505
  • 2
  • 11
  • 30

3 Answers3

2

The thing you want to do is called geocoding, see the page on Google Geocoding API

Update:

Probably you will need this function. It is able to iterate over an array and execute a callback after each geocoding return:

function locate(address, callback) {
    var geocoder = new google.maps.Geocoder(),
        latlong = [];

    geocoder.geocode({
        address: address[0]
    }, function(results, status) {
        if (status === google.maps.GeocoderStatus.OK) {
            latlong.push([results[0].geometry.location.Ma, results[0].geometry.location.Na]);
            address.shift();
            if (typeof callback === 'function') callback(latlong);

            if (address.length === 0) {
                return;
            } else {
                locate(address, callback);
            }
        }
    });
}


/*
 * Sample use
 */
locate(['1 Infinite Loop, Cupertino, CA', '1600 Amphitheatre Parkway, Mountain View, CA'], function(result) {
    console.log(result);
});

Don't forget to include Google Maps API JS file before your script.

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
Lapple
  • 3,207
  • 17
  • 20
0

Use google Geocode API. Also following should help.

string url = string.Format("http://maps.googleapis.com/maps/api/geocode/xml?address={0}&sensor=false", address);

This would return you an xml with following inside node

<location><lat>12.3456</lat><lng>98.7654</lng></location>
Junaid
  • 1,603
  • 16
  • 23
0

I "third" the google geocoder.. here's an example in javascript:

//this is fired on the onChange of a dropdown or textbox
     function SetMap(textbox) {

        var postcode = textbox.value;
        if (postcode != '') {
            var geocoder = new google.maps.Geocoder();
            geocoder.geocode({ 'address': postcode }, GeoCodeResult);

        }

    }

    function GeoCodeResult(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            map.setCenter(results[0].geometry.location);
            var latlng = results[0].geometry.location.lat() + ', ' +                      results[0].geometry.location.lng();

//set hidden field to lat long
            document.getElementById('<%= hdnMapCoords.ClientID %>').value = latlng;


        }
    }
Bex
  • 4,738
  • 10
  • 45
  • 82
  • i want to do the same functionality as saloni wanted . But i want to do it in Asp.net with C# . how can i do it? can you help me ? thanks.. – Rohan Mar 05 '12 at 10:41
  • The above javascript is used with ASP.net and C#. If you are using googles API you have to use Javascript. – Bex Mar 06 '12 at 15:51