Home > Web Front-end > JS Tutorial > body text

JavaScript uses Baidu map api and html5 features to obtain browser location_javascript skills

WBOY
Release: 2016-05-16 17:04:24
Original
1089 people have browsed it

Copy code The code is as follows:



Click this button to get your location:




<script><br>var x=document.getElementById("demo");<br>function getLocation(){<br> if(navigator.geolocation){<br> navigator.geolocation.getCurrentPosition(showPosition); <br> }else{<br> } alert("Your browser does not support geolocation");<br> }<br> } <p>function showPosition(position){<br> lat=position.coords.latitude;<br> lon=position.coords.longitude;<br> //var map = new BMap.Map("container"); / Create Map instance<br> var point = new BMap.Point(lon, lat); // Create point coordinates<br> //map.centerAndZoom(point,15); // <br> //map.enableScrollWheelZoom( ); <br> var gc = new BMap.Geocoder(); <br> gc.getLocation(point, function(rs){<br> var addComp = rs.addressComponents;<br> alert(addComp.province ", " addComp.city ", " addComp.district ", " addComp.street);<br> });<br> }<br></script>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template