Get Latitude and Longitude from your Postal Address

We generally do not know the latitude and longitude of our area or any other area if we have needed to get the information. Sometimes we have to Google for getting this information. It is not a big issue to find out the approximate latitudeĀ  and longitude for any location and it can easily be done in PHP.

latitude-longitude

 

Here I am writing the procedures to do the same.

1. Create a PHP page say ‘postal_lang_long.php’

2. Put the following codes in the PHP file.

<?php
if ($_REQUEST[where]) {
$where = stripslashes($_REQUEST[where]);
$whereurl = urlencode($where);
// Note - Google key is domain specific!
$location = file("http://maps.google.com/maps/geo?q=$whereurl
&output=csv&key=ABQIAAAAvp3__HwvT3VkixIIbsW0axQuKI_6t1bH2P0vC
I_Q8jfpn8qdNBQMnneljxh9czilkau_bYSCXteS_A");
// Sample - $location[0]="200,8,51.369318,-2.133457";
list ($stat,$acc,$north,$east) = explode(",",$location[0]);
$html = "Information for ".htmlspecialchars($where)."
";
$html .= "North: $north, East: $east<br>";
$html .= "Accuracy: $acc, Status: $stat<br>";
} else {
$html = "Space reserved for your report when form completed";
}
?>
<html>
<head>
<title>Postal Address to Latitude / Longitude</title>
</head>
<body bgcolor="#99CCFF"></pre>
<div align="center">500px;"></div>
Enter a place name / address and a latitude and longitude will be returned.
<form method=post>Place: <input type="text" name="where" size="40" />
<input type=submit value=go></form>
</div>
</body>
</html>

3. Now place your PHP file in your web server and open the file in any browser.
4. Now in your browser you can see a text box asking for the name of the place.
5. Enter the place-name and hit ‘go’ button.
6. That’s all, you will be shown the latitude and longitude of your location.

This Post Has 28 Comments

  1. Aaron says:

    Hi there. Great tute! Very useful. I was wondering, if I wanted to use this in my application, should I sign up for my own Google API Key? Or what is the legality of using the same key over and over for multiple websites, say in a template?

  2. Seb says:

    This is fantastic – I've been looking for some solutions for getting lat and long from the post code, but this one is the top-notch one. Thanks for sharing!

  3. Hi,this article is great,I found it on google and I appreciate it very much,I agree with what you have said, it help me a lot in decision,but I still have some questions with the last part,can you explain it for me ?I will appreciate your answer,and I will be back again!

  4. This online internet site carries a pretty good offer of pretty good right lower to earth well finding tips also it will require to hold out tremendously well, if it hasn’t already? I appreciated studying about some even though implementing products!

  5. Jamison Haws says:

    I apperceive i am a smaller away topic, but i just funds to say i adulation the blueprint within the blog. i am new in the route of blogegine platform, so any tips on accepting my internet page analytic good is often appreciated.

  6. Matt Riske says:

    I'm not sure exactly why but this weblog is loading incredibly slow for me. Is anyone else having this issue or is it a problem on my end? I'll check back later on and see if the problem still exists.

    • admin says:

      Hi Matt, I think there are some issues at your end. This website is designed and coded such a way to load faster. There is no external script called and I tried to maintain it simplistic look. If you find this issue later too, please feel free to write is from our contact page.

  7. admin says:

    Hi, this is designed & developed by my team. We are a web development company. We provide web based services. For any future assistance, you can write us from our contact page. We will be happy to assist you.

  8. admin says:

    Hi, thanks for your comments. You can sign up for our blog update through e-mail and you can find it in the footer area. So, when ever I update any post, you will be notified through e-mail.

Leave A Reply