日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > HTML >内容正文

HTML

浏览器获取地理位置

發(fā)布時間:2025/1/21 HTML 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 浏览器获取地理位置 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

轉(zhuǎn)自: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 Test</title><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='<p>Latitude: ' + position.coords.latitude + '</p>' + '<p>Longitude: ' + position.coords.longitude + '</p>' + '<p>Accuracy: ' + position.coords.accuracy + '</p>' + '<p>Altitude: ' + position.coords.altitude + '</p>' + '<p>Altitude accuracy: ' + position.coords.altitudeAccuracy + '</p>' + '<p>Speed: ' + position.coords.speed + '</p>' + '<p>Heading: ' + position.coords.heading + '</p>';}</script></head><body><script language="javascript" type="text/javascript"> if (navigator.geolocation) { document.write('<p><input type="button" οnclick="getLocation()" value="Show Geolocation Information" /></p>');} else { document.write('<p>Sorry, your device or browser software does not appear to support geolocation services.</p>'); } </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!

    轉(zhuǎn)載于:https://www.cnblogs.com/shanghaif/archive/2010/07/20/1781686.html

    總結(jié)

    以上是生活随笔為你收集整理的浏览器获取地理位置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。