Driving
AMap.Driving
Driving route planning service, providing the functionality to query driving navigation routes based on start and end coordinates.
Construct a driving route planning service object, and set its properties through DrivingOptions. DrivingOptions allows setting driving strategies and the level of detail in returned information. Users can retrieve and display query results through custom callback functions. If the service request fails, the system will return error information.
new AMap.Driving(opts: DrivingOptions)Parameter
opts(DrivingOptions): Driving route planning parameters
Demo
AMap.plugin("AMap.Driving", function () {
var drivingOptions = {
map: map,
autoFitView: true,
};
var driving = new AMap.Driving(drivingOptions);
driving.search([
{ keyword: '2 Na Phra Lan Rd, Khwaeng Phra Borom Maha Ratchawang', city: '764010000' },
{ keyword: '34 Wang Doem Rd, Khwaeng Wat Arun', city: '764010000' },
]);
});Method
search(origin, destination, opts, callback)
Implement driving route planning based on the coordinates or names of the starting point, destination, and optional waypoints, with waypoints set via opts
Parameter:
origin (LngLat) Starting Point Latitude and Longitude
destination (LngLat) Destination Latitude and Longitude
opts (Object)
callback (DrivingCallback) When the status is complete, the result is DrivingResult; when the status is error, the result is the error message info; when the status is no_data, it means the search returned 0 results
Demo:
const startLngLat = [100.491422, 13.749313]; //Starting point coordinates
const endLngLat = [100.49, 13.74]; //Destination coordinates
var opts = {
waypoints: [[100.482731, 13.745401]], //Set waypoint parameters, supports up to 16 waypoints
};
driving.search(startLngLat, endLngLat, opts, function (status, result) {
//status: complete indicates a successful query, no_data indicates no results, and error represents a query error
//When the query is successful, the result is the corresponding driving navigation information
});search(points, callback)
Based on the coordinates or names of the start point, end point, and waypoints (optional), implement driving route planning, with waypoints set through opts
Parameter:
points (Array<Object>) The latitude and longitude points of the destination are an array of the names and corresponding cities of the start point, end point, and waypoints (optional)
callback (DrivingCallback) When the status is complete, the result is DrivingResult; when the status is error, the result is the error message info; when the status is no_data, it means the search returned 0 results
Demo:
var points = [
{ keyword: '2 Na Phra Lan Rd, Khwaeng Phra Borom Maha Ratchawang', city: '764010000' }, //Starting point coordinates
{ keyword: '198 Maha Rat Rd, Khwaeng Phra Borom Maha Ratchawang', city: '764010000' }, //Set waypoint parameters, supports up to 16 waypoints
{ keyword: '34 Wang Doem Rd, Khwaeng Wat Arun', city: '764010000' } //Destination coordinates
];
];
driving.search(points, function (status, result) {
//status: complete indicates a successful query, no_data indicates no results, and error represents a query error
//When the query is successful, the result is the corresponding driving navigation information
});clear()
Clear search results
Demo:
driving.clear();setPolicy(policy)
Set driving route planning strategy
Parameter: policy (number) Driving route planning strategy
Demo:
driving.setPolicy(0);