有谁知道iPhone是否支持或即将支持W3C Geolocation specification ?
我希望为移动用户构建一个应用程序,但与其花时间为每个不同的平台(iPhone、Android 等)开发应用程序,我更愿意创建一个网络应用程序,使使用 W3C 标准。
最佳答案
这段代码对我有用——在 iPhone 网络浏览器 Safari 和 作为额外的好处,它甚至可以在我的 FireFox 3.5 上运行笔记本电脑! Geolocation API 规范是 W3 联盟标准的一部分但请注意:它尚未最终确定。
(来源:bemoko.com)
(来源:bemoko.com)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Geolocation API Demo</title>
<meta content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" name="viewport"/>
<script>
function successHandler(location) {
var message = document.getElementById("message"), html = [];
html.push("<img width='256' height='256' src='http://maps.google.com/maps/api/staticmap?center=", location.coords.latitude, ",", location.coords.longitude, "&markers=size:small|color:blue|", location.coords.latitude, ",", location.coords.longitude, "&zoom=14&size=256x256&sensor=false' />");
html.push("<p>Longitude: ", location.coords.longitude, "</p>");
html.push("<p>Latitude: ", location.coords.latitude, "</p>");
html.push("<p>Accuracy: ", location.coords.accuracy, " meters</p>");
message.innerHTML = html.join("");
}
function errorHandler(error) {
alert('Attempt to get location failed: ' + error.message);
}
navigator.geolocation.getCurrentPosition(successHandler, errorHandler);
</script>
</head>
<body>
<div id="message">Location unknown</div>
</body>
</html>
关于javascript - iPhone 上的地理定位 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/221592/