adobe photoshop 60 download

Adobe Premiere Pro CS5 discount free adobe dream weaver 8 download free download adobe distiller cheapest adobe photoshop free download full version where does adobe save download video files

adobe bridge download

Adobe Creative Suite 4 for Mac buy cheap download adobe photoshop elements 5 adobe download free premiere pro buy cheap adobe acrobat 8 download purchase adobe photoshop cs3 extended full download

free adobe download manager

buy cheap Adobe cs5 Design Premium for Mac adobe acrobat reader 6 0 1 free download adobe flashplayer download softpedia discount download adobe after effects download adobe after effects

free download adobe illustrator 9

cheapest Adobe cs5 for Mac adobe cs2 download free crack key generator how to download adobe flash movies cheapest adobe acrobat reader free download adobe 8 free download

free adobe download

Autodesk AutoCAD cheapest adobe download free premiere adobe distiller free download discount download adobe flashplayer free adobe download manager download

adobe audition 1 5 download

cheap AutoCAD Architecture adobe acrobat 8 free download adobe creative suite 2 download cheapest download adobe premiere pro cs3 download adobe reader cd

adobe encore menu download

cheapest Adobe Captivate CS5.5 download adobe ebook reader adobe photoshop elements 3 for mac download cheap download adobe photoshop 7 download adobe flash player

download adobe reader latest version

discount Creative Suite 5.5 download adobe photoshop cs2 adobe photoshop 8 free download full version discount download free adobe standard adobe flas player 9 download

download adobe photoshop mac free

Autodesk AutoCAD discount free adobe 8 download free download of adobe pagemaker buy cheap adobe dream weaver 8 download download adobe scanner

adobe reader download for mac

discount AutoCAD 2010 free adobe download free download of adobe reader buy cheap free download adobe photodeluxe home edition adobe flash player 8 download

adobe lightroom download

AutoCAD LT 2012 buy cheap adobe golive cs2 download freeware adobe acrobat download cheap adobe flash activex download download adobe flashplayer

adobe flash 9 download

adobe acrobat x buy cheap adobe free download software download adobe photoshop cs2 cheap download adobe audition 3 free adobe premiere download

adobe flash offline download

adobe creative suite 5 discount download adobe acrobat reader 8 adobe 9 download discount free adobe photoshop elements 6 download download adobe reader pdf free

search adobe reader 7 0 download

cheap adobe cs5 adobe acrobat writer free download adobe fine reader free download cheap adobe player download center adobe professional download

download adobe flashplayer free

Adobe cs5 Design Premium cheapest where free download adobe acrobat free download of adobe reader buy cheap adobe flash 7 download download adobe reader8

free adobe acrobat writer download

Adobe eLearning Suite cheap download adobe active x download adobe acrobat 7 updates discount download adobe flash 9 for h264 free adobe pdf maker download

adobe photo plus 6 download

discount Adobe eLearning Suite 2 download adobe photoshop cs2 adobe illustrator full crack download cheapest adobe photoshop download site adobe acrobat raeder v7 download

adobe flash player download for windows vista

discount Adobe Flash Catalyst CS5 adobe photo editor download adobe reader 6 free download discount download adobe flashplayer free free download adobe illustrator 9

adobe shockwave player download

discount Adobe Indesign CS5 free adobe dream weaver 8 download adobe photo free download cheapest adobe flash player downloader free download hunter grabber free adobe profesional 8 download

adobe type manager download free

discount Adobe Photoshop CS5 download adobe acrobat reader free old adobe software download discount download adobe flash player stand alone adobe acrobat update download

How to get Longitude and Latitude from an Address using PHP | Geocoding | JSON | Plot on Google Map using Location Address

In my previous article i explained “google-map-integration-using-javascript-php” . In all examples explained in the previous post we used longitude and latitude value to plot the location and we needed to find it manually . In many instance we would need to plot the location using an address . It can be done using a small php script .


$geocode=file_get_contents('http://maps.google.com/maps/api/geocode/json?address=Marine+Drive+GCDA+Complex+Cochin&sensor=false');

$output= json_decode($geocode);

$lat = $output->results[0]->geometry->location->lat;
$long = $output->results[0]->geometry->location->lng;

echo "Latitude : ".$lat;
echo "Longitude : ".$long;

The php code above makes a request to Google maps API using 2 arguments address and sensor . Each word in address should be joined using ‘+’ symbol as show above and the response we get is in json format which is decrypted to get latitude and longitude .

A complete example to plot on Google map using an Address you have .

You need to get a Google Map API to use this code . You can register here for a Google Map API key . Replace ‘ADD_YOUR_KEY_HERE’ with your KEY


<?php
$geocode=file_get_contents('http://maps.google.com/maps/api/geocode/json?address=Maharajas+College+Cochin&sensor=false');
$output= json_decode($geocode);
$latitude = $output->results[0]->geometry->location->lat;
$longitude = $output->results[0]->geometry->location->lng;
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="http://maps.google.com/maps?file=api&v=1&key=ADD_YOUR_KEY_HERE" type="text/javascript"></script>
</head>

<body>
<div id="map" style="width: 400px; height: 300px"></div>

<script type="text/javascript">
var map = new GMap(document.getElementById("map"));
var point = new GPoint(<?php echo $longitude; ?>,<?php echo $latitude; ?>);
var address = 'Maharajas College | Cochin';
var mark = createInfoMarker(point, address);
map.addOverlay(mark);
function createInfoMarker(point, address) {
 var marker = new GMarker(point);
 map.centerAndZoom(point, 3);

 GEvent.addListener(marker, "click",
 function() {
 marker.openInfoWindowHtml(address);
 }
 );
 return marker;
}
</script>

</body>
</html>

The output of above code is

Hope this tutorial helped you ! Comment me if u need any help .

About the Author: a holistic web developer , movie buff and technical blogger from queen of arabian sea.

RSSComments (34)

Leave a Reply | Trackback URL

  1. [...] « Credit Card Number Validation using PHP How to get Longitude and Latitude from an Address using PHP | Geocoding | JSON [...]

  2. priyanka says:

    thanks for this…….it really helps a lot and made my work easier
    great work……keep it up!!!!

  3. nsachc says:

    So sorry I can’t find your name! So, hi. Wonder if you can help put some javascript mapping code into php? please email me with your email address so I can show you what I have, what it does, and what I would like to do with it.

    Many thanks if you can.

  4. anoopsachari says:

    @nsachc mail me @anoop.s.achari@gmail.com

  5. sujikumar says:

    i’ve just mailed you one problem,am a beginer to this developing field..kindly help me..

  6. Ankit says:

    When i run this script on Fedora 10 linux LAMP it give warning
    “Warning: file_get_contents() [function.file-get-contents]: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution”

    why?

  7. anoopsachari says:

    @ankit . i never came across such a issue with the code . try updating your php version to latest version .

  8. Ankit says:

    I’m using php 5.2.14. when i run on command line it works for me & display result as u shown above.

    But when i access it through BROWSER it displays blank

  9. Ankit says:

    Ankit :
    I’m using php 5.2.14. when i run on command line it works for me & display result as u shown above.
    But when i access it through BROWSER it displays blank

    Done Bro.
    I have to enable “allow_url_include”.

  10. anoopsachari says:

    Thank you Ankit for the new info .

  11. nagaraju says:

    good work bro keep it up

  12. Pherum says:

    Hi, it is a good job. and I wonder if I can get the real of users latitude and longitude, because when i rus this I only see exactly the same as your sample.

    Pherum

  13. anoopsachari says:

    @pherum : you can see that in second line i have specified
    “address=Maharajas+College+Cochin” the longitude and latitude values are calculated according to that , you may change it to the address you required so that google maps would plot them accordingly.

  14. John says:

    Hi anoopsachari,

    Nice article.I am just a newbie to google maps.All i am planning is a custom google maps in which a user can log into a site.Then he is shown a text box to search location by zip code.The searched Zip code diameter is shown on the map.The user can click on any area there and mark that place,(like on the click,the exact long and lat is fetched) and the user can add the name and description to that place and all this details are stored in the mysql database and only a logged in user who created this mark should be able to see those marks and it should not be visible on publicly on google maps.

    Please give a hint as how to start on this.

    regards,
    John

  15. anoopsachari says:

    @john : the application you planning to do is a complicated application. i dont know weather google map API provide you permission to highlight a diameter using zipcode.

    second part could be implemented using a mysql db. like logging the info [ longitude and latitude ] marked by the user. so that the next time he login he can view all places marked by him. But the question is . “how will you communicate with the local mysql db when a user marks on google maps ?”

  16. John says:

    Hi anoopsachari,

    Thanks for the prompt answer.I need to know about a Google Maps API function that will give the correct [long and lat] when a user clicks on ANY WHERE on the map.As the user is logged(Mysql user registration and login) into to the map view,then only [long and lat] is collected and for that corresponding [long and lat] we will store the information in the DB.So again when user logins in all the db information for his marked [long and lat] is displayed.It will be using ajax with google map api

    Any further idea on this?

  17. Hi, long time lurker here , just wanted to say how I’m a big fan , but wish you would change your theme! You can get a free wordpress theme here, that’s where I got mine.

  18. gmina says:

    Świetnie to napisałeś :) cieszę się, że wszedłem na tę stronkę, bo bardzo fajnie się czyta.

  19. martin says:

    on prob of the plugin for conversion…..when i double click a text area for full selection ..the text converion menu is shown

  20. Rokun says:

    This is so great I like this code. Thank’s man .

  21. Eugen says:

    Nice, thank you for example :) very helpfull for my new project:D

  22. me says:

    where’s the zoom in and zoom out?

  23. anand godar says:

    Nice tutorial thanks buddy … its reallly a good one

  24. Dan says:

    Nice work. I very quickly was able to get this all up and running. Thank you so much for sharing!!!

  25. subikar says:

    Hey thank you for this help me to do my work more faster. :)

  26. Veena says:

    Hi… google does not understand postal codes? like e.g if i just use 90002 which is Los Angeles in USA it doesnt give right response. I need to use Los Angeles. Do i need to add anything else with the zip code or postal code to find the co-ordinates?

  27. Saroj says:

    Thanks buddy, nice work. keep it up.

  28. shraddha says:

    using php i have to make program which accepts two numbers (latitude and longitude) and converts it into a postal address.can u help that how to get this

  29. MRIGANKA says:

    Hi…really nice code…thanks. but where are the zoom in and zoom out buttons??

  30. abru says:

    id – 1,
    college – auburn,
    zipcode – 36849,
    url – http://www.auburn.edu,
    ipeds is – 100858,
    campus – city,
    latitude – 32.59942,
    logitude – -85.4881,

    pls can you help me with a script for this… pulling from my database of a million rows of the value. and how i can walk it out with pictures given the url and lat. and long.
    thank you

  31. Dhilip says:

    Hello achari,
    i have to display more than one place in this code….is it possible????

  32. Sourabh says:

    missing ) after argument list
    [Break On This Error] var map = new GMap(documentgetElementById(“map”));

    getting this error can u pls reply on this…

    Thanks

  33. Hey very cool web site!! Man .. Beautiful .. Amazing .. I’ll bookmark your website and take the feeds also…I’m happy to find so many useful info here in the post, we need develop more strategies in this regard, thanks for sharing. . . . . .

Leave a Reply

Get Adobe Flash playerPlugin by wpburn.com wordpress themes