早上好朋友,正在研究一个项目,一个在android webview上使用map v3的android项目。我注意到有时我的街景不能正常工作。它有时显示空白。我还注意到我的街景并没有显示这个地址的全景照片"阿森纳,英国伊斯灵顿的伦敦自治市",从那里开始,所有输入的地址都不显示街景全景图片。我也注意到在我测试过的其他应用程序中显示了相同的地址。最后在android webview中进行JavaScript警报工作,我自己的工作不起作用。以下是我的代码。
function initialize() {
geocoder = new google.maps.Geocoder();
var fenway = new google.maps.LatLng(42.345573, -71.098326);
var mapOptions = {
center: fenway,
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP,
streetViewControl: true,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU,
position: google.maps.ControlPosition.TOP_LEFT,
mapTypeIds: [
google.maps.MapTypeId.ROADMAP,
google.maps.MapTypeId.SATELLITE,
google.maps.MapTypeId.TERRAIN,
google.maps.MapTypeId.HYBRID
]
}
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var panoramaOptions = {
position: fenway,
pov: {
heading: 34,
pitch: 10
}
};
panorama = new google.maps.StreetViewPanorama(document.getElementById('pano'), panoramaOptions);
map.setStreetView(panorama);
google.maps.event.addListener(panorama, 'status_changed', function() {
document.getElementById("loading1").style.display = "none";
});
google.maps.event.addListener(map, 'tilesloaded', function() {
document.getElementById("loading").style.display = "none";
});
document.getElementById( "cancel" ).onclick = function() {
document.getElementById("autocomplete").value = "";
};
google.maps.event.addListener(map, 'center_changed', function() {
document.getElementById("loading1").style.display = "none";
});
}
function codeAddress() {
var address = document.getElementById('autocomplete').value;
if(address=='') {
alert("Type a valid address");
}
else {
document.getElementById("loading1").style.display = "block";
var address = document.getElementById('autocomplete').value;
geocoder.geocode( { 'address': address}, function(results, status1) {
if (status1 == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
streetViewService = new google.maps.StreetViewService();
STREETVIEW_MAX_DISTANCE = 100;
streetViewService.getPanoramaByLocation(results[0].geometry.location, STREETVIEW_MAX_DISTANCE, function (streetViewPanoramaData, status) {
if (status == google.maps.StreetViewStatus.OK) {
panorama.setPosition(results[0].geometry.location);
}
if (status == google.maps.StreetViewStatus.UNKNOWN_ERROR) {
alert("Can not be found");
}
else {
alert("Street view not available in your location");
}
});
}
else {
alert('Geocode was not successful for the following reason: ' + status1);
}
});
}
}
<body bgcolor="#F2F2F2" onload="initialize()">
<div id="loading1">
<img id="loading-image1" src="images/loading1.gif" alt="Loading..." />
</div>
<div id="adds"></div>
<div id="loading">
<img id="loading-image" src="images/loading.gif" alt="Loading..." />
</div>
<div id="locationField">
<input id="autocomplete" placeholder="Enter address,city,country" type="text"></input>
<img id="cancel" src="images/cancel.png" alt="Loading..."/>
</div>
<input id="button" type="button" name="test" value="Search" style=" font-size:15pt; background-color:#2E2E2E; color:#2EFEF7;" onclick="codeAddress()">
<div id="pano" style="width: 100%; height: 48%;"></div>
<div id="map-canvas" style="width: 100%; height: 25%;"></div>
</body>
</html>