iPhone上的Geolocation API
-
03-07-2019 - |
题
有谁知道iPhone是否支持或即将支持 W3C地理定位规范
我正在寻找为移动用户构建应用程序,但不是花时间为每个不同的平台(iPhone,Android等等)开发应用程序,我更喜欢创建一个网络应用程序,使使用W3C标准。
解决方案
此代码对我有用 - 在iPhone网络浏览器 Safari 和上作为额外的奖励它甚至可以与 FireFox 3.5 一起使用笔记本电脑!地理位置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>
其他提示
现在,您可以在iPhone 3.0发布之后的Safari浏览器中从Javascript API获取位置 - 我们已经创建了一个工作示例@ http://blog.bemoko.com/2009/06/17/iphone-30-geolocation-javascript-api/
由于iPhone OS 3.0 Safari支持获取地理位置。请参阅: Safari参考库:获取地理位置另一方面,W3C Geo API规范仍处于草案阶段。
我更新了My Whirled View的代码。在我的iOS 4.3设备上运行良好。 Google不再需要API密钥来访问其静态地图库。
<?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>iPhone 4.0 geolocation demo</title>
<meta content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" name="viewport"/>
<script>
function handler(location) {
var message = document.getElementById("message");
message.innerHTML ="<img src='http://maps.google.com/maps/api/staticmap?center=" + location.coords.latitude + "," + location.coords.longitude + "&zoom=14&size=256x256&maptype=roadmap&sensor=false&markers=color:blue%7Clabel:ABC%7C" + location.coords.latitude + "," + location.coords.longitude + "' />";
message.innerHTML+="<p>Longitude: " + location.coords.longitude + "</p>";
message.innerHTML+="<p>Accuracy: " + location.coords.accuracy + "</p>";
message.innerHTML+="<p>Latitude: " + location.coords.latitude + "</p>";
}
navigator.geolocation.getCurrentPosition(handler);
</script>
</head>
<body>
<div id="message">Location unknown</div>
</body>
</html>
这就是我开发Locatable应用程序的原因 - 它本质上是iPhone Safari的插件。目前它仅适用于越狱手机。
可以在iPhone上使用JavaScript获取GPS信息。 QuickConnectiPhone框架为您公开了这一点以及加速信息。
要获取此信息,您必须在设备上安装该应用程序。该框架很快将适用于Android安装的应用程序以及诺基亚。
您可以将应用程序放入每个设备的框架中,进行编译和发布。
可以在 https://sourceforge.net/projects/quickconnect/ 上找到QuickConnectiPhone
如果您与我联系,我可以为您提供适用于Android和诺基亚的预发行版本。
Rhodes 承诺“开发一次运行 - 无处不在”。解。没有自己试过。
这个小型javascript库跨平台,支持开箱即用的所有现代智能手机:
以下是您使用它的方式:
//determine if the handset has client side geo location capabilities
if(geo_position_js.init()){
geo_position_js.getCurrentPosition(success_callback,error_callback);
}else{
alert("Functionality not available");
}
目前,仅使用JavaScript API无法获得iPhone的GPS位置。有人说这很好,但苹果公司当然不会评论公众未来的改进。