Cod*_*eef 40 javascript iphone gps geolocation
有谁知道iPhone是否支持或将很快支持W3C Geolocation规范?
我正在寻找为移动用户构建应用程序,但不是花时间为每个不同的平台(iPhone,Android等等)开发应用程序,我更喜欢创建一个利用W3C标准.
dan*_*lmb 46
这段代码对我有用 - 在iPhone网络浏览器Safari上 ,作为额外的奖励它甚至可以在我的笔记本电脑上使用FireFox 3.5!地理位置API规范是W3联盟标准的一部分但是要注意:它尚未最终确定.
alt text http://blog.bemoko.com/wp-content/uploads/2009/06/iphone-geo-300-1-150x150.jpg alt 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>
Run Code Online (Sandbox Code Playgroud)
小智 7
现在,您可以在iPhone 3.0发布之后的Safari浏览器中从Javascript API获取位置 - 我们已经创建了一个工作示例@ http://blog.bemoko.com/2009/06/17/iphone-30-geolocation-javascript- API /