2011-10-13 36 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

我已经在我的表单中插入了隐藏的输入元素,并通过插入任何地址,如果存在它的经纬度自动插入到隐藏的元素,如果不是,则输入的位置无效。 –