- varmarker = newgoogle.maps.Marker
- (
- {
- position: newgoogle.maps.LatLng(-34.397, 150.644),
- map: map,
- title: ''Click me''
- }
- );
498)this.width=498;'' onmousewheel = ''javascript:return big(this)'' alt="" src="http://images.myeducs.cn/files/uploadimg/20111202/1000584.png" />
Info Window(信息窗口)
我们已经在地图上某个位置加了标记,也为标记添加onclick了事件,点击可以弹出一个窗口来显示该地点的详细信息。我们可以按照下面的代码来创建信息窗口:
- varinfowindow = newgoogle.maps.InfoWindow({
- content: ''Location info:
- Country Name:
- LatLng:''
- });
- google.maps.event.addListener(marker, ''click'', function() {
- // 打开窗口
- infowindow.open(map, marker);
- });
将它们结合起来的代码如下:
- Codevarmap;
- functioninitialize() {
- varlatlng = newgoogle.maps.LatLng(-34.397, 150.644);
- varmyOptions = {
- zoom: 8,
- center: latlng,
- mapTypeId: google.maps.MapTypeId.ROADMAP
- };
- map = newgoogle.maps.Map(document.getElementById("map"), myOptions);
- varmarker = newgoogle.maps.Marker
- (
- {
- position: newgoogle.maps.LatLng(-34.397, 150.644),
- map: map,
- title: ''Click me''
- }
- );
- varinfowindow = newgoogle.maps.InfoWindow({
- content: ''Location info:
- Country Name:
- LatLng:''
- });
- google.maps.event.addListener(marker, ''click'', function() {
- // Calling the open method of the infoWindow
- infowindow.open(map, marker);
- });
- }
- window.onload = initialize;
利用上面的代码,我们将会在页面上创建一张地图,然后定位用户所在的区域,在这个区域加上标记,并且弹出一个显示位置信息的窗口。
498)this.width=498;'' onmousewheel = ''javascript:return big(this)'' alt="" src="http://images.myeducs.cn/files/uploadimg/20111202/1000587.png" />
Multiple Makers(多标记)
有些时候,我们可以要在地图上处理多个标记,那么我们就可以用下面代码来实现:
- Codefunctionmarkicons() {
- InitializeMap();
- varltlng = [];
- ltlng.push(newgoogle.maps.LatLng(40.756, -73.986));
- ltlng.push(newgoogle.maps.LatLng(37.775, -122.419));
- ltlng.push(newgoogle.maps.LatLng(47.620, -122.347));
- ltlng.push(newgoogle.maps.LatLng(-22.933, -43.184));
- for(vari = 0; i <= ltlng.length;i++) {
- marker = newgoogle.maps.Marker({
- map: map,
- position: ltlng[i]
- });
- (function(i, marker) {
- google.maps.event.addListener(marker, ''click'', function() {
- if(!infowindow) {
- infowindow = newgoogle.maps.InfoWindow();
- }
- infowindow.setContent("Message" + i);
- infowindow.open(map, marker);
- });
- })(i, marker);
- }
- }
4