0
我是新來的這個平臺,如果有人可以建議我使用代碼段來查看我的應用是否需要查找谷歌地圖上提供的地址。在地圖上提供地址的位置代碼
我是新來的這個平臺,如果有人可以建議我使用代碼段來查看我的應用是否需要查找谷歌地圖上提供的地址。在地圖上提供地址的位置代碼
的Javascript:
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latitide = 50.445516;
var longitude = 30.452188;
var addressHiddenField = document.getElementById("<%= AddressCoordinates.ClientID %>");
if (addressHiddenField.value.length > 0) {
latitide = parseFloat(addressHiddenField.value.split(";")[0]);
longitude = parseFloat(addressHiddenField.value.split(";")[1]);
}
var latlng = new google.maps.LatLng(latitide, longitude);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
function codeAddress() {
var addressHiddenField = document.getElementById("<%= AddressCoordinates.ClientID %>");
var address = document.getElementById("<%= AddressTextBox.ClientID %>").value;
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
addressHiddenField.value = results[0].geometry.location.lat() + ";" + results[0].geometry.location.lng();
}
else {
addressHiddenField.value = "";
alert("Geocode was not successful for the following reason: " + status);
}
});
}
標記:
<body onload="initialize()">
<form id="form1" runat="server">
<div id="map_canvas" style="width: 100%; height: 480px;">
</div>
<div>
<asp:TextBox runat="server" ID="AddressTextBox" />
<asp:Button runat="server" ID="GetAddressCoordinatesButton" OnClientClick="codeAddress()"
Text="Search Address" />
<hr />
<asp:HiddenField runat="server" ID="AddressCoordinates" />
</div>
</form>
感謝很多的幫助。 – amithotu