google 地图s 怎么显示文字或者数字,且为动态的
google maps 如何显示文字或者数字,且为动态的
如题:
google maps 如何根据经纬度显示文字或者数字,且为动态的。(JavaScript实现)
例:根据给定经纬度,显示一些数字,并且这些数字是动态显示的,每3s或者其他时间显示不同数据!
------解决方案--------------------
显示自定义文本/图片的话,你需要创建一个自定义的覆盖层。给你一个改编自官方谷歌文档的例子,你自己参考一下吧。
如题:
google maps 如何根据经纬度显示文字或者数字,且为动态的。(JavaScript实现)
例:根据给定经纬度,显示一些数字,并且这些数字是动态显示的,每3s或者其他时间显示不同数据!
------解决方案--------------------
显示自定义文本/图片的话,你需要创建一个自定义的覆盖层。给你一个改编自官方谷歌文档的例子,你自己参考一下吧。
//adapded from this example http://code.google.com/apis/maps/documentation/javascript/overlays.html#CustomOverlays
//text overlays
function TxtOverlay(pos, txt, cls, map){
// Now initialize all properties.
this.pos = pos;
this.txt_ = txt;
this.cls_ = cls;
this.map_ = map;
// We define a property to hold the image's
// div. We'll actually create this div
// upon receipt of the add() method so we'll
// leave it null for now.
this.div_ = null;
// Explicitly call setMap() on this overlay
this.setMap(map);
}
TxtOverlay.prototype = new google.maps.OverlayView();
TxtOverlay.prototype.onAdd = function(){
// Note: an overlay's receipt of onAdd() indicates that
// the map's panes are now available for attaching
// the overlay to the map via the DOM.
// Create the DIV and set some basic attributes.
var div = document.createElement('DIV');
div.className = this.cls_;
div.innerHTML = this.txt_;
// Set the overlay's div_ property to this DIV
this.div_ = div;
var overlayProjection = this.getProjection();
var position = overlayProjection.fromLatLngToDivPixel(this.pos);
div.style.left = position.x + 'px';
div.style.top = position.y + 'px';
// We add an overlay to a map via one of the map's panes.
var panes = this.getPanes();
panes.floatPane.appendChild(div);
}