iPhone上的地理定位API [英] Geolocation API on the iPhone
问题描述
有谁知道iPhone是否支持或即将支持 W3C地理定位规范?
我正在为移动用户构建应用程序,而不是花时间为每个不同平台(iPhone,Android等)开发应用程序。 ..),我更愿意创建一个使用W3C标准的Web应用程序。
对于我来说 - 在iPhone网页浏览器 Safari 和上,它甚至可以在我的笔记本电脑上与 FireFox 3.5 一起使用! Geolocation API规范是W3联盟标准的一部分但应该警告:它尚未最终确定。
文字http://blog.bemoko.com/wp-content/ uploads / 2009/06 / iphone-geo-300-1-150x150.jpg 替代文字http://blog.bemoko.com/wp-content/uploads/2009/06/iphone-geo-300-2-150x150.jpg
<?xml version =1.0encoding =UTF-8?>
<!DOCTYPE html PUBLIC - // WAPFORUM // DTD XHTML Mobile 1.0 // ENhttp://www.wapforum.org/DTD/xhtml-mobile10.dtd\">
< html xmlns =http://www.w3.org/1999/xhtml>
< head>
< title> Geolocation API Demo< / title>
< script>
函数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>精确度:,location.coords.accuracy,米< / p>);
message.innerHTML = html.join();
}
函数errorHandler(错误){
alert('尝试获取位置失败:'+ error.message);
}
navigator.geolocation.getCurrentPosition(successHandler,errorHandler);
< / script>
< / head>
< body>
< div id =message>位置未知< / div>
< / body>
< / html>
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.
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 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>
这篇关于iPhone上的地理定位API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!