请问Google Map API怎么根据地址获得经纬度?
请问Google Map API怎么根据地址获得经纬度?
根据输入的地址,获得该地址的经纬度?
求代码
------解决方案--------------------1.<html>
2.<head>
3.<meta http-equiv="Content-Type" content="text ml; charset=utf-8">
4.<title>MAPBaidu-http://www.k686.com</title>
5.<script type="text/javascript" src=" http://api.map.baidu.com/api?key=458d39374361da27e548367a735831ba&v=1.0&services=true" ></script>
6.</head>
7.<body>
8.<div style="position:absolute;width:730px;height:590px;top:50;left:0;border:1px solid gray;overflow-y:hidden;" id="container"></div>
9.<input id="text_" type="text" value="武汉"/>
10.<input type="button" value="search" onclick="searchByStationName();">
11.<a href="http://www.k686.com" target="_blank">k686绿色软件</a>
12.</body>
13.<script>
14.var map = new BMap.Map("container");
15.map.centerAndZoom(new BMap.Point(121.480,31.220), 6);
16.
17.var localSearch= new BMap.LocalSearch (map, {
18. renderOptions: {
19. pageCapacity: 8,
20. autoViewport: true,
21. selectFirstResult: false
22. }
23. });
24.
25. localSearch.enableAutoViewport();
26.function searchByStationName()
27.{
28.
29. var keyword = document.getElementById("text_").value;
30. localSearch.setSearchCompleteCallback(function(searchResult){
31. var poi = searchResult.getPoi(0);
32. alert(poi.point.lng+" "+poi.point.lat);
33. map.centerAndZoom(poi.point, 8);
34. });
35. localSearch.search(keyword);
36.
37.}
38.</script>
39.</html>
(源于http://tuzwu.iteye.com/blog/682699)
------解决方案--------------------JScript code
//同步坐标
function synchronizationCoordinate() {
var url = "http://maps.google.com/maps/api/geocode/json?address=" + encodeURIComponent($('#<%= txtAddress.ClientID %>').val()) + "&sensor=false" + "&randomNum=" + Math.random();
$.ajax({
url: url,
dataType: 'json',
success: function(data) {
if (data.status == 'OK') {
//经度
$('#<%= txtLongitude.ClientID %>').val(data.results[0].geometry.location.lng);
//纬度
$('#<%= txtLatitude.ClientID %>').val(data.results[0].geometry.location.lat);
}
else {
alert("没找到你要查询的位置,请重新输入!");
}
},
error: function() {
alert("网络繁忙,请重试!");
}
});
}
------解决方案--------------------
C# code
/**
* 根据地址返回经纬度
* @param addr
* @return 返回经纬度数据, latLng[0]经度,latLng[1]维度
*/
public static String[] getCoordinate(String addr) {
String[] latLng = new String[2];
String address = null;
try {
address = java.net.URLEncoder.encode(addr, "UTF-8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
;
String output = "csv";
//密钥可以随便写一个key=abc
String key = "abc";
String url = "http://maps.google.com/maps/geo?q=" + address + "&output=" + output + "&key=" + key;
URL googleMapURL = null;
URLConnection httpsConn = nu