朋友们,现在我正在使用谷歌 API 获取位置信息。我正在获取位置信息,但我无法将其存储在变量或隐藏字段中。任何人都可以帮助我知道我在哪里做错了。
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script language="javascript" type="text/javascript">
var map;
var geocoder;// = new google.maps.Geocoder();
var address;
function initialize() {
var latlng = new google.maps.LatLng(document.getElementById("<%=txtLatitude.ClientID %>").value, document.getElementById("<%=txtLongitude.ClientID %>").value);
var myOptions = {
zoom: 5,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map"), myOptions);
var marker = new google.maps.Marker(
{
position: new google.maps.LatLng(document.getElementById("<%=txtLatitude.ClientID %>").value, document.getElementById("<%=txtLongitude.ClientID %>").value),
map: map,
title: 'Click me'
});
geocoder = new google.maps.Geocoder();
geocoder.geocode({ "latLng": latlng }, function(data, status) {
if (status == google.maps.GeocoderStatus.OK) {
address = data[0].formatted_address;
alert(address);
}
});
var infowindow = new google.maps.InfoWindow({
content: 'Location info:' + address + '<br/>LatLng:' + document.getElementById("<%=txtLatitude.ClientID %>").value + ',' + document.getElementById("<%=txtLongitude.ClientID %>").value
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
});
}
window.onload = initialize;
</script>