2008-10-21 29 views

回答

45

此代码为我工作 - 在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> 
+0

无赖!这不再有效!请参阅:http://bemoko.com/blog/iphonegeo – Rimian 2010-07-28 05:50:07

-3

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

+2

W3C的地理定位我相信是由iPhone的即将3.0升级支持。 – hendry 2009-05-08 10:09:42

+0

这个问题有什么发展吗? – Jack 2010-04-25 22:11:44

-1

可以在iPhone上通过JavaScript获取GPS信息。 QuickConnectiPhone框架为您揭示了这一点以及加速信息。

要获取此信息,您将不得不在设备上安装应用程序。该框架即将面向Android安装的应用程序以及诺基亚。

您可以将您的应用程序放入每个这些设备的框架中,编译并发送。

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

,如果你与我联系,我可以给你的Android和诺基亚的预发布版本。

-1

Rhodes是有希望的“开发一次运行无处不在”的解决方案。没有尝试过他们自己。

0

这个差距就是为什么我开发了Locatable应用程序 - 它本质上是iPhone Safari的一个插件。目前它只适用于越狱手机。

http://lbs.tralfamadore.com/

2

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

这个小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"); 
}