日期:2014-05-18 浏览次数:20577 次
//同步坐标
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("网络繁忙,请重试!");
}
});
}
------解决方案--------------------
/**
* 根据地址返回经纬度
* @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