滑鼠點擊地圖上任意一處取得經緯度

Posted on 一月 14, 2009. Filed under: API問題 |

1. 地圖綁上MouseDown事件, 每次點擊地圖後會回傳event及latlng兩個參數
2. 再透過lat()及lng()兩個函式分別取得緯度及經度

function init() {
	var map = new UMap(document.getElementById('map'));
	map.centerAndZoom(new ULatLng(25.035405, 121.520255), 9);
	// 地圖綁上MouseDown事件, 每次點擊地圖回傳Event及latlng兩個參數
	map.addListener('mousedown', function(e, latlng){
		var inputs = document.getElementsByTagName('INPUT');
		inputs[0].value = latlng.lat(); // 取得的緯度值丟入第一個input text
		inputs[1].value = latlng.lng(); // 取得的經度值丟入第二個input text
	});
}

觀看範例

Make a Comment

Make a Comment: ( 5 so far )

blockquote and a tags work here.

5 Responses to “滑鼠點擊地圖上任意一處取得經緯度”

RSS Feed for urmapapi Comments RSS Feed

有辦法把經緯度…各自放在文字方塊裡面嗎?

謝謝^^

Hi Simon,

我已update範例 將取得的經緯度分別丟入input text
麻煩您再看一次範例

範例的經緯度顛倒了!

2.0 及 latest 中 marker 的 mouseout 事件不 work
Code snippet 如下:

function initialize() {
map = new UMap(document.getElementById(『map』));
map.centerAndZoom(new ULatLng(25.035405, 121.520255), 7);
marker = new UMarker(new ULatLng(25.035405, 121.520255)); marker.addListener(『mouseout』,mouseOut);
function mouseOut(){
alert(『mouseOut』);
}
map.addOverlay(marker);
}

感謝提醒,我們會儘快修正


Where's The Comment Form?

Liked it here?
Why not try sites on the blogroll...