難道你不能只是使用正則表達式來檢查輸入的輸入是一個緯度/經度對呢?然後如果它解析那對並直接導航到座標。例如:
var latLngRegex = /^(\-?\d+(\.\d+)?),\s*(\-?\d+(\.\d+)?)$/; //Regex for checking that it is a latlng pair that has been entered
var address = document.getElementById("txt_googlesearch").value;
if (address=='' || address=='Search') {
return;
}
if (latLngRegex.test(address)) //Run the regex against the entered value
{
var coords = address.split(","); //Split the address into 2 decimal values
var mapPoint = new GLatLng(parseInt(coords[0]), parseInt(coords[1])); //Create a gLatLng from the split values
map.setCenter(mapPoint); //Move the map to the entered location
return;
}
//Call Geocoder as before
你能發表一些代碼來證明你在做什麼嗎? – javram 2012-04-19 21:10:54
以下是我目前正在做的事情:[代碼粘貼](http://pastebin.com/LhwkpceK) – ertyu 2012-04-19 21:36:40
因此,要澄清您的問題,您要解釋的是,如果您輸入一個緯度/您使用「txt_googlesearch」標識創建的輸入,您希望地圖能夠集中在該特定位置?而且它曾經通過地理編碼器來這麼做,但現在正在進行反向查找? – javram 2012-04-19 21:43:42