Blog

Newest Post
Blog Archives
Blog Categories

Portfolio

3D Models
Banners
Brochures
Business Cards
Custom Programming
Environments
Flash Projects
Game Design
Image Altering
Web Design

About

Resume
Recommendation Letters

Contact

October 22, 2009

Latitude and Longitude of a location using PHP and Google

Filed under: PHP,The Coding World — admin @ 12:55 pm

The following PHP code will help you acquire the latitude and longitude of a location (using an address, zip code, or city).

Note: Your will be required to have your own domain specific Google API key.

if ($_POST['address']) {
 
$key = ' '; //you will need yo use your own domain specific API key
 
$address = stripslashes($_POST['address']);
 
$addressurl = urlencode($address);
 
$location = file("http://maps.google.com/maps/geo?q=".$addressurl."&output=csv&key=".$key);
 
list ($stat,$acc,$lat,$lng) = explode(",",$location[0]);
 
echo "LAT:".$lat." - LNG:".$lng;
 
}

Below is the HTML code which used a form to submit the address to the above PHP.

<form action="<?php echo $_SERVER['PHP_SELF']; ?>;" method="post">
<input name="address" type="text" />
<input type="submit" value="Submit" />
</form>

Leave a Reply

© - Digital Epiphany Designs, Online Portfolio for Web Design, Custom Programming, Grapic Design and Game Design.