Home  >  Article  >  Web Front-end  >  JavaScript uses Baidu map api and html5 features to obtain browser location_javascript skills

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

WBOY
WBOYOriginal
2016-05-16 17:04:241085browse

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>

Statement:
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