<HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head> <title>Query latitude and longitude based on address</title> <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"> <Scripttype= "Text/javascript"src= "http://api.map.baidu.com/api?v=1.3"></Script></Head><Bodystyle= "background: #CBE1FF"> <Divstyle= "Width:730px;margin:auto;">address to query:<inputID= "Text_"type= "text"value= "Ningbo Tianyi Square"style= "margin-right:100px;"/>query results (latitude and longitude):<inputID= "Result_"type= "text" /> <inputtype= "button"value= "Query"onclick= "Searchbystationname ();"/> <DivID= "Container"style= "Position:absolute; margin-top:30px; width:730px; height:590px; top:50; border:1px solid Gray; Overflow:hidden; "> </Div> </Div></Body><Scripttype= "Text/javascript"> varMap= NewBmap.map ("Container"); Map.centerandzoom ("Ningbo", A); Map.enablescrollwheelzoom (); //Enable wheel Zoom out, disabled by defaultMap.enablecontinuouszoom (); //Enable map inertia drag, disabled by defaultMap.addcontrol (NewBmap.navigationcontrol ()); //Add a default zoom translation controlMap.addcontrol (NewBmap.overviewmapcontrol ()); //add default thumbnail map controlMap.addcontrol (NewBmap.overviewmapcontrol ({isOpen:true, anchor:bmap_anchor_bottom_right})); //Lower right corner, open varLocalsearch= Newbmap.localsearch (map); Localsearch.enableautoviewport (); //allow automatic resizing of forms functionSearchbystationname () {map.clearoverlays ();//clear the original label varkeyword=document.getElementById ("Text_"). Value; Localsearch.setsearchcompletecallback (function(SearchResult) {varPOI=Searchresult.getpoi (0); document.getElementById ("Result_"). Value=POI.POINT.LNG+ "," +Poi.point.lat; Map.centerandzoom (Poi.point, -); varMarker= NewBmap.marker (NewBmap.point (POI.POINT.LNG, Poi.point.lat)); //Create a callout that corresponds to the latitude and longitude of the place to be queriedMap.addoverlay (marker); varcontent=document.getElementById ("Text_"). Value+ "<br/><br/> Longitude:" +POI.POINT.LNG+ "<br/> Latitude:" +Poi.point.lat; varInfowindow= NewBmap.infowindow ("<p style= ' font-size:14px; ' >" +content+ "</p>"); Marker.addeventlistener ("Click", function () { This. Openinfowindow (Infowindow);}); //marker.setanimation (bmap_animation_bounce);//Bounce Animation }); Localsearch.search (keyword);} </Script></HTML>
Baidu Map-Search by address latitude and longitude