0
我怎样才能找到一个iPhone浏览器当前的经度和使用HTML5的用户纬度我怎样才能找到当前经度和使用HTML5
我怎样才能找到一个iPhone浏览器当前的经度和使用HTML5的用户纬度我怎样才能找到当前经度和使用HTML5
地理位置是通过JavaScript地理位置API可用纬度:
https://developer.mozilla.org/En/Using_geolocation
的API通过导航暴露
navigator.geolocation
的API是相同的所有HTML5功能的浏览器并没有什么iPhone SPE它在其中。
<script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3.1&sensor=true"></script>
<script type="text/javascript">
var r = confirm("We need your permission to get your location!");
if (r == true) {
function onPositionUpdate(position) {
document.getElementById("txtlati").value = position.coords.latitude;
document.getElementById("txtlongi").value = position.coords.longitude;
}
if (navigator.geolocation)
navigator.geolocation.getCurrentPosition(onPositionUpdate);
else
alert("navigator.geolocation is not available");
}
else {
x = "Sorry! You will be redirecting";
location.href("Default.aspx");
}
function initialize() {
var map = new google.maps.Map(document.getElementById("map_area"));
var myLatlng = new google.maps.LatLng(document.forms[0].txtlati.value, document.forms[0].txtlongi.value);
var myOptions = { zoom: 15, center: myLatlng, mapTypeId: google.maps.MapTypeId.ROADMAP }
var map = new google.maps.Map(document.getElementById("map_area"), myOptions);
var marker = new google.maps.Marker({ position: myLatlng, draggable: true, flat: false, map: map, title: "Move pin to get latitude and longitude." });
google.maps.event.addListener(marker, "drag", function() {
var latlng = marker.getPosition();
document.forms[0].txtlati.value = latlng.lat();
document.forms[0].txtlongi.value = latlng.lng();
});
}
</script>
<div id="map_area" style="width: 700px; height: 500px">
</div>
我在div.thats它的文本框。
http://mobile.tutsplus.com/tutorials/mobile-web-apps/html5-geolocation/ – 2012-02-24 06:43:13