2011-10-13 34 views
-2

我是一個公司,要求我在谷歌地圖上放一些標記。 我對地址進行了地理編碼,並且使用了經緯度和長度,而不是使用其中的標記將需要很長時間才能加載。緯度和經度提交按鈕

然而,他們現在還問我是否可以做一個簡單的應用程序,以獲得lat和長從地址。因此,一個簡單的地理編碼的應用程序:

一個輸入字段和一個提交按鈕,點擊該按鈕上的經緯度和時長將顯示下方或上方或旁邊。

我可以使用哪個函數來獲取?

我一直在尋找,現在在互聯網上幾天,但我無法找到任何東西,也使得它,這樣我就可以顯示緯度和長期被發現。

我不擅長編程。

+0

您所有的問題都非常相似......。 – Widor

+0

這是另一個任務:o其他人我沒有使用緯度和經度.. 也使用OSM還有因爲其他任務是自由的谷歌API – ronnie

+0

我看到更大的和大的。只是要小心,不要讓他們問我「爲我做我的工作」,就這些。 – Widor

回答

1

我很困惑,你是否想要找到一個地址的lat和lng?

如果是使用谷歌地圖API http://code.google.com/apis/maps/documentation/geocoding/

這裏有一個例子 http://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true

而且會吐回的緯度和經度的JSON格式。

如果你想反向地理東西 http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true

爲了使一個應用程序,有一個提交按鈕,使用jQuery/AJAX做它,把從谷歌服務的結果。

+0

thx會看看它:D – ronnie

-1

可能是這個鏈接將幫助您瞭解反向地理編碼。 getting places from lat and lang

+0

thx爲您的答覆,但我的意思是另一種方式:(他們把地址,並得到拉特和lng或者是否也可以使用該功能以另一種方式進行操作? – ronnie

0

也許給你體驗,你應該嘗試使用gmap3 jQuery的。它使用Google Maps API v3,但將API抽象化,使其更易於使用。他們有你應該學習的example。它需要一個地址並返回一個可能的位置。

下面,我已經修改,這將提醒位置的例子 - 希望給你一個良好的開端:

$("#test").gmap3(); 

$('#address').autocomplete({ 
    //This bit uses the geocoder to fetch address values 
    source: function(request, response) { 
    $("#test").gmap3({ 
     action:'getAddress', 
     address: request.term, 
     callback:function(results){ 
     if (!results) return; 
     response($.map(results, function(item) { 

      alert("The location is", item.geometry.location.lat(), item.geometry.location.lon()); 

      return { 
      label: item.formatted_address, 
      value: item.formatted_address, 
      latLng: item.geometry.location 
      } 
     })); 
     } 
    }); 
    }, 
    //This bit is executed upon selection of an address 
    select: function(event, ui) { 
    $("#test").gmap3(
     {action:'clear', name:'marker'}, 
     {action:'addMarker', 
     latLng:ui.item.latLng, 
     map:{center:true} 
     } 
    ); 
    } 
}); 
+0

thx很多人會看看它:D – ronnie

+0

如何當我嘗試啓動這個腳本我得到一個空的頁面? – ronnie

+0

該腳本作爲__functions__的示例演示,您可以使用它來實現您想要的功能。就這樣。 – Ross

2
function get_tatitude_longitude(address){ 
var mygc = new google.maps.Geocoder(); 
mygc.geocode({'address' : address}, function(results, status){ 
    alert("latitude : " + results[0].geometry.location.lat()); 
    alert("longitude : " + results[0].geometry.location.lng()); 
lat_c = results[0].geometry.location.lat(); 
long_c = results[0].geometry.location.lng(); 
mapa(); 
document.getElementById('lat').value = results[0].geometry.location.lat(); 
document.getElementById('long').value = results[0].geometry.location.lng(); 
document.getElementById('latlongclicked').value = marker.getPosition(); 

}); 

} 
+0

你可以添加一些上下文到你的答案?這段代碼究竟做了什麼? – 2012-10-12 13:03:50

+0

我已經在我的表單中插入了隱藏的輸入元素,並通過插入任何地址,如果存在它的經緯度自動插入到隱藏的元素,如果不是,則輸入的位置無效。 –