Javascript 如何在谷歌地图中编辑默认标记
请查看此地图视图: 如果单击A或B,它将在默认标记中显示位置名称。我想在这里展示一些自定义文本。我该怎么做? 我的JavaScript代码是:Javascript 如何在谷歌地图中编辑默认标记,javascript,google-maps-api-3,Javascript,Google Maps Api 3,请查看此地图视图: 如果单击A或B,它将在默认标记中显示位置名称。我想在这里展示一些自定义文本。我该怎么做? 我的JavaScript代码是: var directionsDisplay; var directionsService = new google.maps.DirectionsService(); var map; var oldDirections = []; var currentDirections = null; //getting latitude and longit
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
var oldDirections = [];
var currentDirections = null;
//getting latitude and longitude from address
var latitude;
var longitude;
var geocoder = new google.maps.Geocoder();
var address = "Downtown Berkeley";
geocoder.geocode( { "address": address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK)
{
// do something with the geocoded result
//
latitude = results[0].geometry.location.lat()
longitude = results[0].geometry.location.lng()
alert(latitude )
}
});
//map initialize
function initialize() {
var myOptions = {
zoom: 13,
center: new google.maps.LatLng(-33.879,151.235),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
//adding marker
var marker = new google.maps.Marker
(
{
position: new google.maps.LatLng(latitude , longitude),
map: map,
title: "Click me"
}
);
var infowindow = new google.maps.InfoWindow({
content: "Location info:<br/>Country Name:<br/>LatLng:"
});
google.maps.event.addListener(marker, "click", function () {
// Calling the open method of the infoWindow
infowindow.open(map, marker);
});
directionsDisplay = new google.maps.DirectionsRenderer({
"map": map,
"preserveViewport": true,
"draggable": true
});
directionsDisplay.setPanel(document.getElementById("directions_panel"));
google.maps.event.addListener(directionsDisplay, "directions_changed",
function() {
if (currentDirections) {
oldDirections.push(currentDirections);
}
currentDirections = directionsDisplay.getDirections();
});
calcRoute();
}
function calcRoute() {
var start = "El Cerrito del Norte";
var end = "Downtown Berkeley";
var request = {
origin:start,
destination:end,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
var方向显示;
var directionsService=new google.maps.directionsService();
var映射;
var oldDirections=[];
var currentDirections=null;
//从地址获取纬度和经度
纬度;
var经度;
var geocoder=new google.maps.geocoder();
var address=“伯克利市中心”;
geocoder.geocode({“address”:address},函数(结果,状态){
if(status==google.maps.GeocoderStatus.OK)
{
//对地理编码的结果做些什么
//
纬度=结果[0]。几何体。位置。纬度()
经度=结果[0]。几何体。位置。lng()
警报(纬度)
}
});
//映射初始化
函数初始化(){
变量myOptions={
缩放:13,
中心:新google.maps.LatLng(-33.879151.235),
mapTypeId:google.maps.mapTypeId.ROADMAP
}
map=new google.maps.map(document.getElementById(“map_canvas”),myOptions);
//添加标记
var marker=new google.maps.marker
(
{
位置:新google.maps.LatLng(纬度、经度),
地图:地图,
标题:“点击我”
}
);
var infowindow=new google.maps.infowindow({
内容:“位置信息:
国家名称:
拉丁美洲:
});
google.maps.event.addListener(标记“单击”,函数(){
//调用infoWindow的open方法
信息窗口。打开(地图、标记);
});
directionsDisplay=新建google.maps.DirectionsRenderer({
“地图”:地图,
“保存视口”:正确,
“可拖动”:正确
});
directions display.setPanel(document.getElementById(“directions_panel”);
google.maps.event.addListener(directionsDisplay,“directions\u changed”,
函数(){
如果(当前方向){
oldDirections.push(当前方向);
}
currentDirections=directionsDisplay.getDirections();
});
calcRoute();
}
函数calcRoute(){
var start=“北塞里托岛”;
var end=“伯克利市中心”;
var请求={
来源:start,
目的地:完,
travelMode:google.maps.Directions travelMode.DRIVING
};
路由(请求、功能(响应、状态){
if(status==google.maps.directionstatus.OK){
方向显示。设置方向(响应);
}
});
}
您可以在createInfoWindow()方法中设置该内容。的可能重复项