Route system in PHP using the Google Maps API

3

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

I'm not kidding, I've never worked with the Google Maps API, does anyone have any tips, or help? And the question you do not want to shut up, do you have to pass these 10 addresses in the XML client (or other type) example to Google Maps calculate the shortest route and show me this route?

Thanks to everyone, as the saying goes, do not offend!

    
asked by anonymous 06.02.2015 / 01:15

1 answer

1

For this you can use the Google Distance Matrix API to get the distance and travel time to an array of sources 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 their location, on requests:

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

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

Mandatory Parameters

  • origins : One or more textual latitude / longitude addresses and / or values, separated by the vertical bar character (|), from which distance and time are calculated. If you report an address as a sequence, the service geocodes the sequence and converts it to a latitude / longitude coordinate to calculate the routes. If you enter coordinates, make sure there is no space between latitude and longitude values.

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

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

Optional Parameters

  • mode : Specifies which means of transport to use when calculating routes. Valid values are:
    • driving (default) : Indicates standard traffic routes using the road network.
    • walking : Requests footpaths and sidewalks (where available).
    • bicycling : Requests bike routes on bike paths and preferred streets ( currently available only in the US and some cities in Canada ).
    • language : The language in which results are to be returned. Check the list of supported domain languages . The list of supported languages is updated frequently; therefore, it is not definitive.
    • avoid : Enters constraints on the route. Valid values are specified in the Restrictions section of this document. You can only specify a constraint.
    • units : Specifies the system units to use when expressing distance as text. See the Systems section of this document for more information.

Route information can be obtained by entering the unique origin and destination you want for Google Directions API .

    
06.02.2015 / 01:55