<!DOCTYPE html> <html> <head> <title>Geolocation API Example: Listening for Location Updates</title> <meta http-equiv="X-UA-Compatible" content="IE=9" /> <script type="text/javascript"> function setText(val, e) { document.getElementById(e).value = val; } var nav = null; var watchID; function listenForPositionUpdates() { if (nav == null) { nav = window.navigator; } if (nav != null) { var geoloc = nav.geolocation; if (geoloc != null) { watchID = geoloc.watchPosition(successCallback); } else { alert("geolocation not supported"); } } else { alert("Navigator not found"); } } function clearWatch(watchID) { window.navigator.geolocation.clearWatch(watchID); } function successCallback(position) { setText(position.coords.latitude, "latitude"); setText(position.coords.longitude, "longitude"); } </script> </head> <body> <label for="latitude">Latitude: </label><input /> <label for="longitude">Longitude: </label><input /> <input type="button" value="Watch Latitude and Longitude" /> <input type="button" value="Clear watch" /> </body> </html>
实用参考: 官方文档: 脚本之家:https://www.jb51.net/w3school/html5/ 微软帮助:(v=vs.85) 百度地图API:
(编辑:ASP站长网)
|