欢迎访问 生活随笔!

尊龙游戏旗舰厅官网

当前位置: 尊龙游戏旗舰厅官网 > 前端技术 > html >内容正文

html

浏览器获取地理位置 -尊龙游戏旗舰厅官网

发布时间:2025/1/21 html 6 豆豆
尊龙游戏旗舰厅官网 收集整理的这篇文章主要介绍了 浏览器获取地理位置 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

转自:http://smithsrus.com/gps-geolocation-in-safari-on-iphone-os-3-0/

gps geolocation in safari on iphone os 3.0

i just updated my iphone to the shiny new os 3.0. apple did a great job addressing a few shortcomings and adding new features. others have alreadytold about the common features so i won’t rehash them here.

but let me tell you about my favorite new feature: safari can now get your gps location via javascript! this is usually referred to as geolocation. you can easily grab the current location or get periodic updates.

okay, so i’m excited over what may seem like an obscure geeky feature, but i think it’s a big deal.

why gps in safari is a big deal

  • location aware web pages: have you ever gone to a company’s web site to find their nearest location? you usually have to type in your zip code. but what if you’re traveling and don’t know your zip code? safari knowing your location solves that problem.

  • location aware web applications: it’s fairly easy to create web content looks and behaves like an iphone application. now those can take advantage of location information.

    for example, i’ve been working with a company on an iphone web application that interacts with their internal customer database. field reps can now easily find customers within a certain radius of the rep’s current location who meet various other criteria.

  • web geolocation privacy and standards

    don’t worry, all of this is built with good privacy controls. you are asked permission before your location data is revealed to a site. for convenience, it stops asking about a particular site after you have approved it a few times.

    these location features are based on the upcoming geolocation api specification. because it’s not just a proprietary safari thing it should get widespread adoption. in fact, it’s already built into the latest firefox 3.5 beta.

    web geolocation sample code

    the specifications do a good job of explaining the parts so no need to go over all of that. however, it’s worth pointing out how to check and see if geolocation features are available or not and take appropriate action. for example, you may only want to show gps options if it can actually be used. this simple snippet will do the job.

    if (navigator.geolocation) { /* code if geolocation is available. */ } else { /* code if geolocation is not available */ }

    let’s put it all together in a simple web page that displays all of the geolocation variables for your current location. the code is below or you can try mygeolocation test page from your iphone.

    (yes, you’ll probably want to use modern dom techniques for a real project. the purpose of this is just to show a simple working example.)

    doctype html> <html lang="en"><head><meta http-equiv="content-type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" /><title>geolocation testtitle><script language="javascript" type="text/javascript">function getlocation() {// get location no more than 10 minutes old. 600000 ms = 10 minutes.navigator.geolocation.getcurrentposition(showlocation, showerror, {enablehighaccuracy:true,maximumage:600000});}function showerror(error) {alert(error.code ' ' error.message);}function showlocation(position) {geoinfo.innerhtml='

    latitude: ' position.coords.latitude '

    '
    '

    longitude: ' position.coords.longitude '

    '
    '

    accuracy: ' position.coords.accuracy '

    '
    '

    altitude: ' position.coords.altitude '

    '
    '

    altitude accuracy: ' position.coords.altitudeaccuracy '

    '
    '

    speed: ' position.coords.speed '

    '
    '

    heading: ' position.coords.heading '

    '
    ;}script>head><body><script language="javascript" type="text/javascript"> if (navigator.geolocation) { document.write('

    '
    );} else { document.write('

    sorry, your device or browser software does not appear to support geolocation services.

    '
    ); } script><div id="geoinfo">div>body> html>

    i can’t wait to see some of the great things others will create by combining web sites with location. and it will only get better as more devices become location aware. be sure to let me know of good location-aware sites and web apps you run across.

    now go create something cool!

    转载于:https://www.cnblogs.com/shanghaif/archive/2010/07/20/1781686.html

    总结

    以上是尊龙游戏旗舰厅官网为你收集整理的浏览器获取地理位置的全部内容,希望文章能够帮你解决所遇到的问题。

    如果觉得尊龙游戏旗舰厅官网网站内容还不错,欢迎将尊龙游戏旗舰厅官网推荐给好友。

    • 上一篇:
    • 下一篇:
    网站地图