How to load google maps api with a route to an address?

0

I installed the Maps API, but I do not know how to get a result, which would load the map with the best route between two addresses, I'm using javascript and html.

    
asked by anonymous 10.10.2017 / 19:47

1 answer

0

add this code to your html:

<iframe width="600" height="450" frameborder="0" style="border:0"
src="https://www.google.com/maps/embed/v1/directions?key=SUA_API_KEY_AQUI&origin=endereco+de+origem&destination=endereco+do+destino&mode=driving" allowfullscreen></iframe>

The following URL parameters are required:

origin: defines the starting point from which to display the route. The value can be the name of a place, an address, or a place ID. The string must have URL escape. This means that addresses such as "City Hall, New York, NY" (City Hall, New York, NY) are to be converted to City + Hall, New York, NY. (The Google Maps Embed API allows + and% 20 to escape from spaces.) Location IDs must be preceded by place_id :. destination defines the route's arrival point.

The following URL parameters are optional:

waypoints: specifies one or more intermediate places to provide route guidance between the source and the destination. You can specify multiple reference points using the vertical bar character (|) to separate places (for example: Berlin, Germany | Paris, France). You can specify up to 20 waypoints. Each reference point can be the name of a place, an address, or a place ID.

mode: defines the mode of transport. The options are driving, walking (which gives preference to pedestrian paths and sidewalks, when available), bicycling (which generates routes by cycle paths and preferred streets, when available), transit or flying. If no mode is specified, the Google Maps Embed API will display one or more of the modes most relevant to the specified route.

avoid: instructs Google Maps to avoid tolls, ferries and / or highways. Separate values with the vertical bar character (for example: avoid = tolls | highways). Note that this action does not exclude routes that include the constrained components; it simply directs the result to more favorable routes.

units: specifies metric or imperial units when displaying distances in results. If units are not specified, the query's originating country will determine the units used.

You can use javascript to change the value of "origin" and "destination" dynamically;)

source: link

    
24.05.2018 / 07:27