iPhone 上的地理定位 API

发布于 2024-07-08 16:00:51 字数 195 浏览 8 评论 0原文

有谁知道iPhone是否支持或即将支持W3C地理定位规范

我希望为移动用户构建一个应用程序,但与其花时间为每个不同的平台(iPhone、Android 等)开发应用程序,我更愿意创建一个利用W3C 标准。

Does anyone know whether the iPhone supports or will soon support the W3C Geolocation specification?

I'm looking to build an app for mobile users, but rather than spend the time developing apps for every different platform (iPhone, Android, etc...), I'd much prefer to create a web app that makes use of the W3C Standard.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

十年不长 2024-07-15 16:00:51

这段代码对我有用——在 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>

This code worked for me -- on the iPhone web browser Safari and as an added bonus it even worked with FireFox 3.5 on my laptop! The Geolocation API Specification is part of the W3 Consortium’s standards But be warned: it hasn’t been finalized as yet.

alt text
(source: bemoko.com) alt text
(source: 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>
等往事风中吹 2024-07-15 16:00:51

现在,您可以在 iPhone 3.0 发布后从 Safari 浏览器中的 Javascript API 获取位置 - 我们创建了一个工作示例 @ http://blog.bemoko.com/2009/06/17/iphone-30-geolocation-javascript-api/

You can now get location from Javascript APIs in the safari browser following the iPhone 3.0 release - we've created a working example @ http://blog.bemoko.com/2009/06/17/iphone-30-geolocation-javascript-api/

我早已燃尽 2024-07-15 16:00:51

从 iPhone OS 3.0 开始,Safari 支持获取地理位置。 请参阅:Safari 参考库:获取地理位置< /a> 另一方面,W3C Geo API 规范仍处于草案阶段。

Since iPhone OS 3.0 Safari supports getting geo location. See: Safari Reference Library:Getting Geographic Locations On the other side W3C Geo API specification is still in draft.

偷得浮生 2024-07-15 16:00:51

我更新了 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>

I updated MyWhirledView's code. Works great on my iOS 4.3 device.
Google no longer requires an API key to access their static map library.

<?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>
看海 2024-07-15 16:00:51

这个差距就是我开发 Locatable 应用程序的原因——它本质上是 iPhone Safari 的插件。 目前仅适用于越狱手机。

请参阅http://lbs.tralfamadore.com/

This gap is why I developed the Locatable application -- it's essentially a plug-in for iPhone Safari. Currently it's only available for jailbroken phones.

See http://lbs.tralfamadore.com/

满栀 2024-07-15 16:00:51

可以在 iPhone 上使用 JavaScript 获取 GPS 信息。 QuickConnectiPhone 框架为您公开了这一点以及加速信息。

但是,要获取此信息,您必须在设备上安装该应用程序。 该框架很快将可用于 Android 安装的应用程序以及诺基亚。

您可以将应用程序放入每个设备的框架中,进行编译和发布。

QuickConnectiPhone 可在 https://sourceforge.net/projects/quickconnect/ 获取

,如果您与我联系我可以为您提供 Android 和诺基亚的预发布版本。

It is possible to get the GPS information in JavaScript on the iPhone. The QuickConnectiPhone framework exposes this for you as well as acceleration information.

To get this information you will have to install the application on the device however. This framework will soon be available for Android installed applications as well as Nokia.

You can put your application into the framework for each of these devices, compile, and ship.

QuickConnectiPhone is available at https://sourceforge.net/projects/quickconnect/

and if you contact me I can give you pre-release versions for Android and Nokia.

£噩梦荏苒 2024-07-15 16:00:51

Rhodes 承诺提供“一次开发,随处运行”的解决方案。 我自己还没有尝试过。

Rhodes is promising a "develop-once-run-everywhere" solution. Haven't tried them myself.

季末如歌 2024-07-15 16:00:51

这个小型 JavaScript 库是跨平台的,并且开箱即用地支持所有现代智能手机:

<块引用>

http://code.google.com/p/geo-location-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");
}

This small javascript library is cross-platform and supports all modern smartphones out of the box:

http://code.google.com/p/geo-location-javascript/

Here is how you use it:

//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");
}
如果没有你 2024-07-15 16:00:51

目前,仅使用 JavaScript API 无法获取 iPhone 的 GPS 位置。 有人说这会很好,但苹果当然不会公开评论未来的改进。

Currently, it's not possible to obtain an iPhone's GPS position using just JavaScript APIs. There's been talk that this would be nice, but of course Apple won't comment on future improvements in public.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文