Jump to content

UK Postcode Search


billy_111

Recommended Posts

Hi,

 

I don't know how how difficult this is but i need to create a postcode search on the following site:

 

http://www.babiesinthecity.co.uk/sea...ton=&search=M1

What you can see here is a set of "Reviews" which are being pulled out of a database. Each review has a postcode.

 

Now what i need to show on this page is the distance the inputted postcode which is "M1" is to each review.

 

I know i need an API, and i looked into http://code.google.com/apis/maps/documentation/directions/#XML

 

The site is coded in PHP, but i don't quite know how or where to begin? Can anyone point me in the right direction?

 

Thanks

Link to comment
Share on other sites

Hi

 

You can get lists of postcodes and grid refernences. Full details lists are expensive but I think you can find free copies linking partial postcodes to grid references (depends how accurate you want it to be).

 

You could possibly do this in javascript but it would seem better to do it on the database when you extract the details for the review.

 

All the best

 

Keith

Link to comment
Share on other sites

Thanks!

 

I was actually trying to get the following code to work:

 

    public function LoadXml($origin, $destination){

        $xml = simplexml_load_file("http://maps.google.com/maps/api/directions/xml?origin=".$origin."&destination=".$destination."&sensor=false");
        
        foreach ($xml->xpath('//distance') as $distance):
            $lastvalue = $distance->value;
        endforeach;

        $total = $lastvalue * 0.00062137119;
        $total = number_format($total, 2);
        
        return $total;
    }

 

I call the method from the front end like this;

 

                                $review = Review::searchAllReviewsByTitlePoscodeAndAddress();
			while($row = mysql_fetch_array($review)){ 
                                             $pcode = PostcodeSearch::LoadXML($_GET['search'], $row['postcode']);
                                       }

 

But it gives me an error saying it can't recognize "$lastvalue"..

 

Any ideas?

 

Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.