PHP route system using Google Maps API

Asked

Viewed 3,099 times

3

I’m finishing a system in PHP, where the client asked if it has how, generate a route between companies, and generate the shortest, for example, it has 50 companies registered in the database, with address and everything else, he wants, select for example 10 of these companies to make deliveries, what he asked me was: I can select the 10 companies, and the system redeem the addresses, and he (with the help of the google API) calculate the shortest route between these 10 points? I answered "good question" haha.

Joking aside, I’ve never worked with the Google Maps API, does anyone have any tips, or help? And the question you don’t want to shut up, is how to pass these 10 addresses in the client example by XML (or other type) for Google Maps to calculate the shortest route and show me this route?

Thank you all, as the saying goes:!

  • Related question: http://answall.com/q/49505/132

1 answer

1


For this you can use the Google Distance Matrix API for distance and travel time to an array of origins and destinations. This service does not return detailed route information.

The Distance Matrix API has the following format:

http://maps.googleapis.com/maps/api/distancematrix/output?parameters

The HTTPS protocol is recommended for applications that include sensitive user data such as your location:

https://maps.googleapis.com/maps/api/distancematrix/output?parameters

In both cases, output can be in JSON or XML.

Mandatory parameters

  • rigins: One or more latitude/longitude text addresses and/or values, separated by the vertical bar character (|), from which distance and time are calculated. If you give an address as a sequence, the service encodes the sequence and converts it into a latitude/longitude coordinate to calculate the routes. If you give coordinates, check if there is no space between latitude and longitude values.

    origins=Bobcaygeon+ON|41.43206,-81.38992
    
  • Destinations: One or more latitude/longitude text addresses and/or values, separated by the vertical bar character (|), for which distance and time are calculated. If you give an address as a sequence, the service encodes the sequence and converts it into a latitude/longitude coordinate to calculate the routes. If you give coordinates, check if there is no space between latitude and longitude values.

    destinations=Darling+Harbour+NSW+Australia|24+Sussex+Drive+Ottawa+ON|Capitola+CA
    
  • sensor: Indicates if your app is using a sensor (for example, a GPS locator) to determine the user’s location. This value should be true or false.

Optional parameters

  • mode: Specifies which mode of transport to use when calculating routes. Valid values are:
    • Driving (): Indicates standard traffic routes using the road network.
    • Walking: Requests walking routes by pedestrian lanes and sidewalks (where available).
    • bicycling: Requests bike routes on cycle paths and preferred streets (currently only available in the US and some cities in Canada).
    • language: The language in which the results should be returned. See list of supported domain languages. The list of supported languages is updated frequently; therefore, it is not definitive.
    • avoid: Enter restrictions on the path. Valid values are specified in the section Restrictions of this document. Only one restriction can be specified.
    • Units: Specifies the drive system to be used when expressing distance as text. See Systems of units in this document for more information.

The journey information can be obtained by informing the unique origin and destination desired for the Google Directions API.

  • Wooow thank you very much friend. More enlightening impossible. Big hug

Browser other questions tagged

You are not signed in. Login or sign up in order to post.