Tag: IDT This SAR stat cat ble pre Height object
First to register Baidu map API.
1, login Baidu map open platform http://lbsyun.baidu.com
To register an account, complete the information, click on the "API console" in the top right corner of the website, click and create the app.
Application type selection: "Browser side", app service Select all, referer Whitelist: *
Click Submit. An Access application (AK) is generated.
AK code down, on the back of the page to use it to elicit Baidu map.
2. Create HTML pages. Some of the code is as follows:
<!DOCTYPE HTML><HTML> <Head> <MetaCharSet= "Utf-8"> <title></title <!--introduce Baidu Map API, set your own key - <Scripttype= "Text/javascript"src= "Http://api.map.baidu.com/api?v=2.0&ak= just created the application AK"></Script> </Head> <Body> <label>Latitude:</label> <inputtype= "text"ID= "Lat"value=""ReadOnly>
<label>Longitude:</label> <inputtype= "text"ID= "LNG"value=""ReadOnly>
<label>Address:</label> <inputtype= "text"ID= "Address"ReadOnly> <Buttontype= "button"ID= "Open">Click Show Map to get the latitude and longitude of the address</Button> <DivID= ' Allmap 'style= ' width:60%, height:60%, Position:absolute, Display:none '></Div> </Body></HTML>
3. JS Code
<script type= "Text/javascript" >document.getElementById (' Open '). onclick =function () { if(document.getElementById (' Allmap '). style.display = = ' None ') {document.getElementById (' Allmap '). style.display = ' block '; } Else{document.getElementById (' Allmap '). style.display = ' None '; } } varMap =NewBmap.map ("Allmap"); varGEOC =NewBmap.geocoder ();//Address Resolution Object varMarkersarray = []; varGeolocation =Newbmap.geolocation (); varPoint =NewBmap.point (116.404412, 39.914714); Map.centerandzoom (Point,12);//Center PointGeolocation.getcurrentposition (function(r) {if( This. getStatus () = =bmap_status_success) { varmk =NewBmap.marker (R.point); Map.addoverlay (MK); Map.panto (R.point); Map.enablescrollwheelzoom (true); } Else{alert (' Failed ' + This. GetStatus ()); }}, {enablehighaccuracy:true}) Map.addeventlistener ("Click", Showinfo); //Clear Identity functionclearoverlays () {if(Markersarray) { for(IinchMarkersarray) {Map.removeoverlay (Markersarray[i])}} } //mark on Map functionAddmarker (point) {varMarker =NewBmap.marker (point); Markersarray.push (marker); Clearoverlays (); Map.addoverlay (marker); } //Click map Time Processing functionShowinfo (e) {document.getElementById (' LNG '). Value =e.point.lng; document.getElementById (' Lat '). Value =E.point.lat; Geoc.getlocation (E.point,function(RS) {varAddcomp =rs.addresscomponents; varAddress = addcomp.province + addcomp.city + addcomp.district + addcomp.street +Addcomp.streetnumber; if(Confirm ("OK, Address +"?)) {document.getElementById (' Allmap '). style.display = ' None '; document.getElementById (' Address '). Value =address; } }); Addmarker (E.point); } </script>
:
PS: One thing to note is that the JS code should be written behind the body. Otherwise, it doesn't show.
JS by choosing Baidu Map address to get latitude and longitude automatically fill in the text box method