Javascript Google Maps API,在获取方向时设置标记的名称
我有一个程序,允许用户为一次旅行选择多个项目。该程序的一部分将项目映射到谷歌地图中。我使用lat/long坐标生成航路点,然后API从那里获取。最后的地图显示了路线和标记。我想给每个标记一个自定义名称,而不是当前显示的默认街道地址。这可能吗Javascript Google Maps API,在获取方向时设置标记的名称,javascript,google-maps,Javascript,Google Maps,我有一个程序,允许用户为一次旅行选择多个项目。该程序的一部分将项目映射到谷歌地图中。我使用lat/long坐标生成航路点,然后API从那里获取。最后的地图显示了路线和标记。我想给每个标记一个自定义名称,而不是当前显示的默认街道地址。这可能吗 //Display the route on the map $.post("processors/getMapWayPoints.php",{ tripID: tripID }, function(e){
//Display the route on the map
$.post("processors/getMapWayPoints.php",{
tripID: tripID
}, function(e){
console.log("Return is " + e);
latlong = JSON.parse(e);
//iterate through each locations lat/long and add it to the mappoints array for the route plotting
for(var i = 0; i < latlong.length; i+=3){
var name = latlong[i];
var lat = latlong[i+1];
var lng = latlong[i+2];
//create google lat/long point object
var pt = new google.maps.LatLng(lat, lng);
//add the location to the array for the route
mappoints.push({location:pt, stopover:true});
//not being used yet
pointNames.push(name);
}
var mapOptions = {
zoom:11,
center: home
}
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
directionsDisplay.setMap(map);
var request = {
origin:home,
destination:home,
waypoints: mappoints,
//optimizeWaypoints: true,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(result);
}
});
});
//在地图上显示路线
$.post(“processors/getMapWayPoints.php”{
tripID:tripID
},功能(e){
console.log(“返回为”+e);
latlong=JSON.parse(e);
//迭代每个位置(lat/long),并将其添加到路线打印的mappoints数组中
对于(变量i=0;i
您想在哪里“为每个标记指定一个自定义名称”?是方向盘吗?在地图上?您所说的“自定义名称”是什么意思?当单击时,地图上显示的每个标记将以弹出/迷你模式显示地址。我想显示的不是地址,而是姓名。这些标记大多用于餐馆或公共场所。你想为每个标记定制吗?你的意思是?或者?查看源代码不工作?