Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 609713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:35:45+00:00 2026-05-13T17:35:45+00:00

Hay, I wondering how to work out distance between 2 post codes using PHP

  • 0

Hay, I wondering how to work out distance between 2 post codes using PHP and Google Maps Api.

Any one got any idea or links to examples.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T17:35:45+00:00Added an answer on May 13, 2026 at 5:35 pm

    Assuming you are looking for the geographic distance, first you need to get the latitude and longitude of your two postcodes with the Google Maps server-side geocoding services as in the following example:

    $url = 'http://maps.google.com/maps/geo?q=EC3M,+UK&output=csv&sensor=false';
    
    $data = @file_get_contents($url);
    
    $result = explode(",", $data);
    
    echo $result[0]; // status code
    echo $result[1]; // accuracy
    echo $result[2]; // latitude
    echo $result[3]; // longitude
    

    Then you can calculate the distance between the coordinates of your two postcodes by using a great-circle distance implementation such as the following:

    • Snipplr – Calculate distance between two coordinates in PHP

    Note that the server-side geocoding service may only be used in conjunction with displaying results on a Google map; geocoding results without displaying them on a map is prohibited by the Google Maps API Terms of Service License Restrictions.


    UPDATE:

    If you are looking for the driving distance instead of the geographical distance, note that there is no documented and approved method at the moment to access the Google Maps Directions API via an HTTP request on the server-side.

    Nevertheless, an undocumented method that returns a JSON output is the following:

    http://maps.google.com/maps/nav?q=from:London%20to:Dover
    

    This will return you the driving directions, along with the total driving distance in JSON format: "meters":122977.

    The format of the q parameter should be from:xxx%20to:yyy. Replace xxx and yyy with the start and destination respectively. You can use latitude and a longitude coordinates instead of full addresses:

    http://maps.google.com/maps/nav?q=from:51.519894,-0.105667%20to:51.129079,1.306925
    

    Note that not only this is undocumented, but it may also violate the restrictions 10.1 and 10.5 of the Google Maps API Terms and Conditions.

    You may also be interesting in checking out the following related articles:

    • Stack Overflow: Calculate driving directions using PHP?
    • Getting distance using GDirections via URL
    • Retrieve driving directions from google maps with server-side HTTP calls and show results with static maps for WAP
    • Google Maps and Directions, REST Interface?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 377k
  • Answers 377k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Since you tagged this selenium-rc, I assume you use rc.… May 14, 2026 at 8:50 pm
  • Editorial Team
    Editorial Team added an answer In PHP, $$ means you are about to inflict years… May 14, 2026 at 8:50 pm
  • Editorial Team
    Editorial Team added an answer Generally, I would favour consistency. But sometimes there are strong… May 14, 2026 at 8:50 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.