有谁知道iPhone是否支持或即将支持W3C Geolocation specification?iPhone上的地理定位API
我正在为移动用户构建一个应用程序,而不是花时间为每个不同的平台(iPhone,Android等)开发应用程序,我更愿意创建一个Web应用程序使用W3C标准。
有谁知道iPhone是否支持或即将支持W3C Geolocation specification?iPhone上的地理定位API
我正在为移动用户构建一个应用程序,而不是花时间为每个不同的平台(iPhone,Android等)开发应用程序,我更愿意创建一个Web应用程序使用W3C标准。
此代码为我工作 - 在iPhone网页浏览器Safari和作为额外的奖励,它甚至可以在我的笔记本电脑上使用FireFox 3.5!地理定位API规范是W3联盟标准的一部分但请注意:它尚未最终确定。
alt text http://blog.bemoko.com/wp-content/uploads/2009/06/iphone-geo-300-1-150x150.jpgalt text http://blog.bemoko.com/wp-content/uploads/2009/06/iphone-geo-300-2-150x150.jpg
<?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上通过JavaScript获取GPS信息。 QuickConnectiPhone框架为您揭示了这一点以及加速信息。
要获取此信息,您将不得不在设备上安装应用程序。该框架即将面向Android安装的应用程序以及诺基亚。
您可以将您的应用程序放入每个这些设备的框架中,编译并发送。
QuickConnectiPhone可在https://sourceforge.net/projects/quickconnect/
,如果你与我联系,我可以给你的Android和诺基亚的预发布版本。
Rhodes是有希望的“开发一次运行无处不在”的解决方案。没有尝试过他们自己。
这个差距就是为什么我开发了Locatable应用程序 - 它本质上是iPhone Safari的一个插件。目前它只适用于越狱手机。
您现在可以从的JavaScript API获得继iPhone 3.0版本的Safari浏览器的位置 - 我们已经创建了一个工作示例@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>
这个小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");
}
无赖!这不再有效!请参阅:http://bemoko.com/blog/iphonegeo – Rimian 2010-07-28 05:50:07