How to convert zipcode to longitude and latitude?

I want to find the longitude and latitude of a place using zipcode. Can anyone tell me how to do this?

Example in actionscript, which is very helpful for me. Because I am doing a project in Flex.

Zee relationship

+2


source to share


6 answers


Do you have access to the long / lat database? if not, I believe you can use the google maps API for this search.

Oh, I just noticed Chris's answer. I am not familiar with geonames. You can also check out " http://freegeographytools.com/ " which has a ton of geocoding resources, gps, etc. For a variety of projects.



Ahhh ... I just visited Eric's blog post. It is perfectly! I will definitely check with google for more details in a future project.

+2


source


If you are looking for on-demand geocoding use Google. They provide a simple version of the smallpox web service.

I wrote a blog about this a while ago. See this link for step by step instructions for using this simple geocoding.



Cheers, Eric

+2


source


I got the solution, you can also

function getLatLong($code) {
  $mapsApiKey = 'ABQIAAAAsV7S85DtCo0H9T4zv19FoRTdT40ApbWAnDYRE0-JyP5I6Ha9-xT9G5hCQO5UtOKSH5M3qhp5OXiWaA';
  $query = "http://maps.google.co.uk/maps/geo?q=".urlencode($code)."&output=json&key=".$mapsApiKey;
  $data = file_get_contents($query);
  // if data returned
  if($data) {
    // convert into readable format
    $data = json_decode($data);
    $long = $data->Placemark[0]->Point->coordinates[0];
    $lat = $data->Placemark[0]->Point->coordinates[1];
    return array('Latitude'=>$lat, 'Longitude'=>$long);
  } else {
    return false;
  }
}

      

+2


source


multiple places to get zip code databases in multiple formats. Download it to your favorite RDBMSs and request away.

Alternatively, you can use someone else's webservice to look at its value. Other answers have posted possible web services; Also, geocoder.us seems to support Zip Search now.

+1


source


This is now the best solution for this using the latest Google Maps API (v3). Below is a slightly modified example from multiple sources . I have to give them most of the loans. It's PHP using cURL to fetch data from Google, but you can use Ajax as well.

function address_lookup($string){

   $string = str_replace (" ", "+", urlencode($string));
   $details_url = "http://maps.googleapis.com/maps/api/geocode/json?address=".$string."&sensor=false";

   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $details_url);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   $response = json_decode(curl_exec($ch), true);

   // If Status Code is ZERO_RESULTS, OVER_QUERY_LIMIT, REQUEST_DENIED or INVALID_REQUEST
   if ($response['status'] != 'OK') {
    return null;
   }

   $geometry = $response['results'][0]['geometry']['location'];

    $array = array(
        'lat'     => $geometry['lat'],
        'lng'     => $geometry['lng'],
        'state'   => $response['results'][0]['address_components'][3]['short_name'],
        'address' => $response['results'][0]['formatted_address']
    );

    return $array;

}

$zip= '01742';

$array = address_lookup($zip);
print_r($array);

      

0


source


The easiest way is to use GoogleMap Api. Let's say you have zipcode in your $ zipcode variable.

$latlongUrl = 'http://maps.googleapis.com/maps/api/geocode/json?components=postal_code:'.$zipcode;

    $data = file_get_contents($latlongUrl); // you will get string data
    $data = (json_decode($data)); // convert it into object with json_decode
    $location = ($data->results[0]->geometry->location); // get location object

      

$ location is a latitude and longitude object.

0


source







All Articles