


html5 navigator.geolocation obtains geographical location code case based on browser
1. Introduction
html5 Provides the geolocation attribute for window.navigator, which is used to obtain the current user's geography based on the browser Location.
Window.navigator.geolocation provides 3 methods:
void getCurrentPosition(onSuccess,onError,options); //获取用户当前位置 int watchCurrentPosition(onSuccess,onError,options); //持续获取当前用户位置 void clearWatch(watchId); //watchId 为watchCurrentPosition返回的值 //取消监控 options = { enableHighAccuracy,//boolean 是否要求高精度的地理信息 timeout,//获取信息的超时限制 maximumAge//对地理信息进行缓存的时间 } //options可以不写,为默认即可
2. PositionObject
When the geographical location information is successfully obtained, The position object will be returned in the onsuccess method. Through this object, you can obtain relevant information about the geographical location, including:
position对象的属性: latitude,//纬度 longitude,//经度 altitude,//海拔高度 accuracy,//获取纬度或者经度的精度 altitudeAccurancy,//海拔高度的精度 heading,//设备前景方向。正北方向的顺时针旋转角 speed,//设备的前进速度 m/s timestamp,//获取地理位置信息时候的时间
3. Example based on google map
Look at the code directly :
<!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"> <title>在页面上使用google地图示例</title> </head> <body onload = 'init()'> <div id="map" style='width:800px;height:800px;'></div> <script type="text/javascript" src='http://maps.google.com/maps/api/js?sensor=false'></script> <script type="text/javascript"> function init(){ if(navigator.geolocation){ navigator.geolocation.getCurrentPosition(function(pos){ var coords = pos.coords; var latlng =new google.maps.LatLng(coords.latitude,coords.longitude); var options = {zoom:14,center:latlng,mapTypeId : google.maps.MapTypeId.ROADMAP}; var map1; map1 =new google.maps.Map(document.getElementById('map'),options); var marker =new google.maps.Marker({ position : latlng, map : map1 }); var infowindow =new google.maps.InfoWindow({ content : '当前位置!' }); infowindow.open(map1,marker); }); } } </script> </body> </html>
The above is the detailed content of html5 navigator.geolocation obtains geographical location code case based on browser. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.
