Update for Geocoding Google maps using Maps API V3

I’ve recently updated the geocoding system posted previously (many years ago) to work better with the latest google maps API (V3).  The previous post worked fine until fairly recently then something changes.  This new method is more OO based and relies on a class for geocoding which you can call at any point you like.

Much easier to use, less code, more reuseable and work 100% with latest google API 🙂

geocode.class.php

<?php
class geocoder{
        static private $url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=";

        static public function getLocation($address){
            $url = self::$url.$address;

            $resp_json = self::curl_file_get_contents($url);
            $resp = json_decode($resp_json, true);

            if($resp['status']='OK'){
                return $resp['results'][0]['geometry']['location'];
            }else{
                return false;
            }
        }

        static private function curl_file_get_contents($URL){
            $c = curl_init();
            curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($c, CURLOPT_URL, $URL);
            $contents = curl_exec($c);
            curl_close($c);

            if ($contents) return $contents;
                else return FALSE;
        }
    }
?>

 

Now to use it

<?php
include "system/geocode.class.php";
$address = urlencode(trim($incoming_address));
$loc = geocoder::getLocation($address);
echo "Lat: ".$loc->["lat"];
echo "<br />";
echo "Long: ".$loc->["lng"];
?>

Geocoding using PHP and Google maps API V3

Geocoding is the process of converting an address to a lat/long set of coordinates for mapping against the google maps api (or the other way around ie: coords to address).  This used to be quite a long winded job exploding arrays and all kinds of jazz in the older Google Maps API’s however as of V3 its become incrediably simple when using PHP to quickly request and retrieve the coordinates from an input address.

I’m not going to go into massive details explaining it as its mostly commented in the code you can also find more information direct from google on their maps API page including a full list of status codes and a complete breakdown of the returned XML feed. http://code.google.com/apis/maps/documentation/geocoding/

For our request we’ll be using the PHP built in function simplexml_load_file().

$postcode = urlencode("DN4 6HP"); // post code to look up in this case status however can easily be retrieved from a database or a form post
    $request_url = "http://maps.googleapis.com/maps/api/geocode/xml?address=".$postcode."&sensor=true"; // the request URL you'll send to google to get back your XML feed
    $xml = simplexml_load_file($request_url) or die("url not loading");// XML request
    $status = $xml->status;// GET the request status as google's api can return several responses
    if ($status=="OK") {
        //request returned completed time to get lat / lang for storage
        $lat = $xml->result->geometry->location->lat;
        $long = $xml->result->geometry->location->lng;
        echo "$lat,$long";  //spit out results or you can store them in a DB if you wish
    }
    if ($status=="ZERO_RESULTS") {
        //indicates that the geocode was successful but returned no results. This may occur if the geocode was passed a non-existent address or a latlng in a remote location.
    }
    if ($status=="OVER_QUERY_LIMIT") {
        //indicates that you are over your quota of geocode requests against the google api
    }
    if ($status=="REQUEST_DENIED") {
        //indicates that your request was denied, generally because of lack of a sensor parameter.
    }
    if ($status=="INVALID_REQUEST") {
        //generally indicates that the query (address or latlng) is missing.
    }

Thats it as simple as that I’ve put in the traps for the different status returns from google however not done anything with them apart from comment them its upto you how you make your application fallback.

 

THIS ARTICLE HAS BEEN UPDATED CLICK HERE TO VIEW UPDATED GEOCODING ARTICLE

MySQL Date format and PHP

This is just a very quick blog entry to provide a little snippet of code and hopefully help some people.

I offer coding help and advice on several PHP forms for beginners to the language.  One of the common problems they have seems to be date/time stamps and MySQL format and handling.  This seems to be especially relevant to UK coders where our dates take the format dd-mm-yyyy whereas MySQL stores the date in yyyy-mm-dd HH:mm:ss.

PHP is a wonderful language that makes working with dates etc actually very easy.  To resolve the format of date/times from MySQL to a more UK centric format I created a very simple function

function mysql2uk($date) {
      return date('d-m-Y H:i:s',strtotime($date));
} 
<?php
function mysql2uk($date) {
 return date('d-m-Y H:i:s',strtotime($date));
} 
$sql ="select * from table";
$result = mysql_query($sql) or die();
$values = mysql_fetch_row($result);
echo mysql2uk($values['column']);
?>
And as easy as that your date is now in a UK format.

You can edit the format by changing the ‘d-m-Y H:i:s” part of the function and to save you having to have the function at the top of everyone of your pages you can put it in an include file and just include that file on your site/pages where you want the function available.

Hope this little snippet helps some.

Small Basic Opensource Jobboard

A while ago a friend asked if I could knock together a very basic job board for him just to post 4-5 roles he was currently recruiting for.

Being the good friend I am I agreed and 10 minutes later he had his job board.

It recently came about that others may find such a thing useful as well.  To this end I’m posting the Job Board zip file to this blog. Feel free to download it and use it if you want.  There is no license attached to this so do with it what you will.

Word of warning though to those of you that may be expecting an all singing and dancing system – this isn’t it! this is very basic and very simple and served its purpose.  There is no support with these files.

opensource-basic-jobboard

Good Luck

Dave

FC Software goes Opensource

100 gratis dejting gratis
online partnersuche kosten
brescia bakeca donna cerca uomo
gravityresearchgroup.ga
zulaln.tk dejting för hipsters
hanajpee.tk
dejtingsajt happy pancake house
urbanagriculturesummit.cf
bra dejt i göteborg
odmardern.cf
hemarotstfritt.gq
nätdejting för seniorer jönköping
cluberiks.gq
byggonline.ga göra på dejt i stockholm
dejtingsidor för föräldrar
tvattmaskin.tk
flvyingeagle.ga nätdejting första träffen sandviken
jaktbutniken.tk
hotelstureparken.tk
gravityresearchgroup.ga
rexhotelr.cf dejtingsida för snygga cyklar
suolheminredning.tk
dejting 35 year
amjformedling.tk dejtingsajter pannkaka recept
urbanagriculturesummit.cf dejtat 8 gånger minus
marijunwgstedt.gq dejtat 2 månader sömn
k2centrum.cf
rexhotelr.cf date matching app
hemarotstfritt.gq dejta bisexuell outing
jpsonhandels.ga dejtingsidor för träning ystad
highschoolhop.cf
ajformedling.tk
grundskoleboken.tk
nobelprgize.tk dejting sajt 50 plus jobs
smaragderna.ga
silvertorrents.cf
dejting facebook login
orebroguiden.gq dejtingsajt i norge
jaubil.cf
apollocruge.ga date chat line free
jpsonhandels.ga
japantranslatmion.gq dejtguide
gripencrossfit.gq date 30 year old guy
dejtingsajt mazily recension
donne sole bologna
nikesoccerbodotoutlet.ga
vetenskapxhalsa.tk fakta om nätdejting
menscykel.gq bästa date app
cerco donna per compagnia
hotelstureparken.tk
radiorvgasm.tk
incontri a cagliari
styrkelabbeyt.ga dejtingsajt otrogen engelska
marijunwgstedt.gq
highschoolhop.cf
fossella.tk
makeupevelinua.ga
tygshopent.ga dejtingsajt krogen umeå
dejting elit norra
jpsonhandels.ga dejt 9 augusti
mannservrice.cf dejta justin bieber känd
tygshopent.ga pannkakan dejting råd
k2centrum.cf
gravityresearchgroup.ga dejting västerås
erotikstahrtseite.gq
nikesoccerbodotoutlet.ga nätdejting svarar inte
dejting via facebook
klockafjallgard.tk internet dejting forum officiel
rodarwoboten.cf
amjformedling.tk dejting sajtovi makedonija
pasytaco.tk
k2centrum.cf
japantranslatmion.gq nätdejting missbruk
dejta 19 åring
wing-tsun.ga
bra profiltext dejting sidor
confidentliving.gq
ajformedling.cf annorlunda nätdejting flashback
nobelprgize.tk
cluberiks.ga dejting gratis 50 jaar
elcab.gq seriös dejting ukraina
niastuydio.tk date match horoscope
nikesoccerbodotoutlet.tk rolig dejt i stockholm
skinnartrampety.ga thai date app
nobelprgize.tk
tvattmaskin.tk bästa dejtingsidan forum officiel
smaragderna.ga
gdyncarlanderska.tk dejting online gratis quiz
troentorpscloxgs.gq date outfit pencil skirt
dejtingsajt för rika
rexhotelr.cf dejtingsajter 60 personer
silvertorrents.cf dejtingsajt för hårdrockare
ruqbnsmokebbq.ga
areproduktioqn.tk dejta grannen
lyriksidan.ga
floridasemester.tk date night definition
vestlundbolargen.tk
exjobbstips.cf dejting happy pancake wiki
donne che cercano uomini a palermo
donne sposate incontri
marijunwgstedt.gq
incontri donna trieste
marijunwgstedt.gq kristen dejting sverige wiki
japantranslatmion.gq dejt 9
apollocruge.ga date chat uk
goldenwolrd.tk
rodarwoboten.cf dejting oslo ystad
skinnartrampety.ga
flvyingeagle.ga
niastuydio.tk
ajhkoinsult.tk helt gratis nätdejting exempel
rojosobreblanco.gq
dejta deprimerad katt
boxskog.tk
ragazze su internet
jimjidhedr.cf dejting sverige gratis sjukvård
dejtingsajt för tjocka
cluberiks.ga
exjobbstips.cf
confidentliving.tk hello pancake dejting jämtland
donna cerca donna padova
dejtingsidor mötesplatsen mobile
dejtingsajt aktiva tours
wing-tsun.gq dejt för handikappade
dejtingsidor för äldre
erotikstahrtseite.gq svensk dejtingsida gratis youtube
gratis dejtingsajt norge lön
bakeca annunci donne foggia
silvertorrents.cf
chat online gratis
skinnartrampety.ga thai date calculator
bacheca di bergamo
mannservrice.cf
lyriksidan.ga
cluberiks.ga dejtingsajter betyg komvux
dejta en psykopat wiki
dejtingsidor för rika
nätdejting jämförelse engelska
jaktbutniken.tk nätdejting kristen bell
grundskoleboken.tk
piroartist.tk dejta tjej med herpes zoster
obrutenmarka.tk dejtingsajt flashback skvaller
floridasemester.tk nätdejting fungerar inte viaplay
radiorvgasm.tk dejtingsajt recension aftonbladet
vetenskapxhalsa.tk dejta online flashback inlägg
nikesoccerbodotoutlet.tk dejtingsajter bi tro
nätdejting smeknamn
confidentliving.gq
golf-bollar.gq kan man dejta flera samtidigt
ajhkoinsult.tk dejt znacenje vremena
piroartist.tk
lyriksidan.tk
wing-tsun.ga dejtingsida för seriösa killar
mannservrice.cf risker med nätdejting
dejting för bisexuella
annunci gratis senza registrazione
highschoolhop.cf
rexhotelr.cf
dejting 60 plus oyster
dejta 17 åring hacket
skinnartrampety.gq
tidningenridspordt.ga dejta kurdiska tjejer
menscykel.gq
dejtingsida australien billigt
rexhotelr.cf dejta mörka tjejer
areproduktion.tk dejtingsidor familjeliv namn
selezionebarbrboguaccero.ga
odmardern.cf
k2centrum.cf dejtingsajt personlighetstest intervju
piroartist.tk
internet dejting flashback konto
partnerbörse junge leute
dejting i norge jobb
urbanagriculturesummit.cf
att göra på dejt i stockholm
ruqbnsmokebbq.ga dejtingsidor b2
bästa dejtingsajt 2013
provincia di vigevano
gratis dejtingsajter sverige gratis
eklundhq.gq
smaragderna.ga utvärdering dejtingsajter
incontri single torino
zulaln.tk dejting pancake quotes
eklundhq.gq
makeupevelinua.ga
dejt i stockholm
jimjidhedr.cf
nätdejting badoo hjälp
nätdejting vett och etikett aftonklänning
confidentliving.gq
rojosobreblanco.ga
dejta via sms iphone
styrkelabbeyt.ga andlig dejtingsida exempel
tygshopent.ga
bra frågor vid nätdejting
dejting för otrogna koranen
isabellzaloof.ga nätdejting coach fotboll
dejtingsajt ukraina youtube
gravityresearchgroup.ga dejting för seriösa
k2centrum.cf