2013-02-25 49 views
0

请检查该地图视图:http://gmaps-samples-v3.googlecode.com/svn/trunk/map_language/map_lang.html如何在谷歌编辑默认标记映射

如果你点击了A或B,它会显示在默认位置标记名称。我希望在这里展示一些自定义文本。我怎样才能做到这一点? 这个我的JavaScript代码是:

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); 
    } 
}); 
} 
+0

[如何将商家/“默认”位置标记和infoWindow添加到Google地图(v3)](http://stackoverflow.com/questions/14454782/how-to-add-a-business-默认位置的标记和信息窗口到谷歌-MAPS-v)的 – 2013-02-25 09:24:03

回答

0

您可以设置在createInfoWindow()方法的内容。