goolge地图中查看经纬度
纬度:
放大倍数:
// TextualZoomControl 是一种 GControl 控件,可以显示文本"放大"和"缩小"按钮。 // (取代Google 地图上对应的图标按钮)
function TextualZoomControl() { } TextualZoomControl.prototype = new GControl();
// 为每个按钮创建一个 DIV,并将其放在容器 DIV 中, // 然后返回容器 DIV 作为我们的控件元素。将该控件添加到 // 地图容器中,并将其返回,以便地图类能正确地放置它。 TextualZoomControl.prototype.initialize = function(map1) { var container = document.createElement("div");
var zoomInDiv = document.createElement("div"); this.setButtonStyle_(zoomInDiv); container.appendChild(zoomInDiv); zoomInDiv.appendChild(document.createTextNode("放大")); GEvent.addDomListener(zoomInDiv, "click", function() { map1.zoomIn(); });
var zoomOutDiv = document.createElement("div"); this.setButtonStyle_(zoomOutDiv); container.appendChild(zoomOutDiv); zoomOutDiv.appendChild(document.createTextNode("缩小")); GEvent.addDomListener(zoomOutDiv, "click", function() { if (map1.getZoom() >2) { map1.zoomOut(); } });
map1.getContainer().appendChild(container); return container; }
// 默认情况下,该控件将在地图的左上角显示,边距为 7 像素。 TextualZoomControl.prototype.getDefaultPosition = function() { return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7, 7)); }
// 设置给定按钮元素的正确 CSS。 TextualZoomControl.prototype.setButtonStyle_ = function(button) { button.style.textDecoration = "underline"; button.style.color = "#0000cc"; button.style.backgroundColor = "white"; button.style.font = "small Arial"; button.style.border = "1px solid black"; button.style.padding = "2px"; button.style.marginBottom = "3px"; button.style.textAlign = "center"; button.style.width = "6em"; button.style.cursor = "pointer"; }
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(39.917, 116.397), 4);
GEvent.addListener(map,"click", function(overlay,latlng) {
document.getElementById("lat").value =latlng.lat();
document.getElementById("lng").value =latlng.lng();
document.getElementById("grade").value =map.getZoom();
});
// map.addControl(new GLargeMapControl());
map.enableScrollWheelZoom();
map.addControl(new TextualZoomControl());
// 创建本地搜索控件并将其添加到地图
var lsc = new google.maps.LocalSearch();
map.addControl(new google.maps.LocalSearch(),
new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(150,10)));
}
}
initialize();
window.onunload =function() { GUnload();
}
欢迎转载,请注明出处:亲亲宝宝