【发布时间】:2010-09-18 07:22:07
【问题描述】:
有谁知道 iPhone 是否支持或即将支持W3C Geolocation specification?
我希望为移动用户构建一个应用程序,但与其花时间为每个不同的平台(iPhone、Android 等)开发应用程序,我更愿意创建一个网络应用程序,使使用 W3C 标准。
【问题讨论】:
标签: javascript iphone geolocation gps
有谁知道 iPhone 是否支持或即将支持W3C Geolocation specification?
我希望为移动用户构建一个应用程序,但与其花时间为每个不同的平台(iPhone、Android 等)开发应用程序,我更愿意创建一个网络应用程序,使使用 W3C 标准。
【问题讨论】:
标签: javascript iphone geolocation gps
这段代码对我有用 -- 在 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>
【讨论】:
您现在可以在 iPhone 3.0 发布之后在 safari 浏览器中从 Javascript API 获取位置 - 我们创建了一个工作示例 @http://blog.bemoko.com/2009/06/17/iphone-30-geolocation-javascript-api/
【讨论】:
自 iPhone OS 3.0 起,Safari 支持获取地理位置。请参阅:Safari Reference Library:Getting Geographic Locations 另一方面,W3C Geo API 规范仍在草稿中。
【讨论】:
我更新了 MyWhirledView 的代码。在我的 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 安装的应用程序以及诺基亚。
您可以将您的应用程序放入这些设备的框架中,编译并发布。
QuickConnectiPhone 可在https://sourceforge.net/projects/quickconnect/ 购买
如果您联系我,我可以为您提供 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 位置。有人说这会很好,但苹果当然不会公开评论未来的改进。
【讨论】: