【发布时间】:2014-10-09 09:29:04
【问题描述】:
好吧,我正在尝试查找给定地址的纬度和经度。地址来自文本区域,然后当我单击按钮时,它会给我输入地址的纬度和经度作为警报。我是使用以下脚本:
<script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3&sensor=false&key=AIzaSyDVk87DSFyZlxmYAM8NPNr8sZPN60FYLNA"></script>
<script type="text/javascript">
function calculateCoordinates() {
var lblStreetAddress = document.getElementById('<%= lblStreetAddress.ClientID%>');
var lblLandmark = document.getElementById('<%= lblLandmark.ClientID%>');
var lblCity = document.getElementById('<%= lblCity.ClientID%>');
var lblState = document.getElementById('<%= lblState.ClientID%>');
var lblZipCode = document.getElementById('<%= lblZipCode.ClientID%>');
var txtLatitude = document.getElementById('<%= txtLatitude.ClientID%>');
var txtLongitude = document.getElementById('<%= txtLongitude.ClientID%>');
var address = lblStreetAddress.value + ', ';
address += lblLandmark.value + ', ';
address += lblCity.value + ', ';
address += lblZipCode.value + ', ';
address += lblState.value;
var geocoder;
geocoder = new google.maps.Geocoder();
geocoder.geocode({ address: address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var location = results[0].geometry.location;
txtLatitude.value = location.lat();
txtLongitude.value = location.lng();
}
else
alert(searchString + ' - not found');
});
}
</script>
<asp:TextBox id="txtLatitude" runat="server" Width="100px"></asp:TextBox>
<asp:TextBox id="txtLongitude" runat="server" Width="100px"></asp:TextBox>
这绝对没问题,但我真正想要的是 1.我想使用标签而不是文本区域,因为地址应该来自数据库。 2.我想将纬度和经度值传递给几个标签,以便我可以将它们存储回数据库中。
有可能吗?如果没有,有没有其他不那么复杂的替代方法?
【问题讨论】:
-
stackoverflow.com/questions/19232822/… 能满足您的需求吗?
标签: javascript asp.net google-maps