javascript - iPhone 上的地理定位 API

标签 javascript iphone geolocation gps

有谁知道iPhone是否支持或即将支持W3C Geolocation specification

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

最佳答案

这段代码对我有用——在 iPhone 网络浏览器 Safari 作为额外的好处,它甚至可以在我的 FireFox 3.5 上运行笔记本电脑! Geolocation API 规范是 W3 联盟标准的一部分但请注意:它尚未最终确定。

alt text
(来源:bemoko.com) alt text
(来源: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>

关于javascript - iPhone 上的地理定位 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/221592/

相关文章:

javascript - 包含指向文件夹中所有 .htm 文件的链接的目录

JavaScript Prompt() 显示两次

ios - 从电话簿中获取的联系号码中删除空格

iphone - 如何在使用 facebook-ios-sdk 的应用程序中实现聊天

postgresql - 包含覆盖世界的六边形网格坐标的表格

javascript - Firefox 3.6 - location.href 在 JSP 中不起作用

javascript - 将html添加到div而不替换其中的当前内容

ios - Swift:IOS7 设备上的核心数据 -> 第二个实体上的 entityForName 为 nil

android - 如何在Android上获取当前位置

python - 使用 Pandas 中的两个地理数据框获取最近的距离