我的网站上有地理位置-我可以用javascript获得位置,但我不能在android设备上使用网络视图获得位置。我使用同一个网站,但它不起作用。
我的网站:https://www.ardakazanci.thecompletewebhosting.com/petsHelper/paylasim.php
我安卓代码:
public class MainActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("https://www.ardakazanci.thecompletewebhosting.com/petsHelper/paylasim.php");
}
}
它在网络上工作得很好。不能与WebView一起工作。谢谢。
错误:
地理位置服务失败
我的JavaScript代码- paylasim.php
<script>
// Note: This example requires that you consent to location sharing when
// prompted by your browser. If you see the error "The Geolocation service
// failed.", it means you probably did not give permission for the browser to
// locate you.
function initMap() {
var outputlat = document.getElementById('latitude'); // Enlemi tutsun
var outputlng = document.getElementById('longitude'); // Boylamı tutsun
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 15
});
var infoWindow = new google.maps.InfoWindow({map: map});
// HTML 5 ile geo location olayının sağlanması
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
outputlat.value = position.coords.latitude;
outputlng.value = position.coords.longitude;
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
infoWindow.setPosition(pos);
infoWindow.setContent('Lokasyon bulundu.');
map.setCenter(pos);
}, function () {
handleLocationError(true, infoWindow, map.getCenter());
});
} else {
// Eğer browser desteklemiyor ise
handleLocationError(false, infoWindow, map.getCenter());
}
}
function handleLocationError(browserHasGeolocation, infoWindow, pos) {
infoWindow.setPosition(pos);
infoWindow.setContent(browserHasGeolocation ?
'Error: The Geolocation service failed.' :
'Error: Your browser doesn\'t support geolocation.');
}
</script>
2条答案
按热度按时间j8ag8udp1#
请尝试以下代码:
还要确保在清单中设置权限:
xxhby3vn2#
盲目地返回这不是一个答案,您需要在调用回调之前检查权限