A long time ago to help the uncle solved a GPS coordinate conversion to Baidu map coordinates problem. Today, Uncle told me Baidu map positioning is not allowed. I looked up the API and used a set of functions given by the authorities.
1 //To Create a query object2 varGeolocation =Newbmap.geolocation ();3 4 //Call the GetCurrentPosition function5Geolocation.getcurrentposition (function(position) {6 7 //If the query succeeds8 if( This. Getstatu () = = ' Bmap_statu_success ') {9 Ten //creates a tag mask from a point object and adds it to the map One varMarker =NewBmap.marker (position.point); A Map.addoverlay (marker); - - //Set the center of the map to get the current position the Map.panto (position.point) - } -})
I did not try completely, and the actual address deviation is very large, the deviation of a few kilometers, this must not be. So I check the information on the Internet to know that the location of the Baidu map is offset.
Of course my final solution is not to pass this API and then remove offsets, and I'm using a different approach.
That is, using HTML5 to bring your own positioning. Before I gave the uncle to solve the problem is to convert GPS coordinates to Baidu map coordinates, so I would like to HTML5 the location to get GPS coordinates.
It turns out that this is possible.
That is, do not use Baidu itself to provide the API, and use the HTML5 API, and the resulting results to use Baidu's conversion coordinates of the API to convert. It's a word that sounds around the mouth.
1, call Navigator.geolocation.getCurrentPosition (callback); Function
2, the registration callback function, in the callback function calls Baidu coordinates the conversion API, this API uncle knows, I did not investigate, only knew can through the URL to request and registers a callback, but BMAP provides one such function, I here first assumes is Convgps (X,y,from,to, callback);
What do these parameters mean?
X: Longitude
Y: Latitude
From: To convert the type of coordinates, Baidu official website has 1 for international GPS coordinates, 2 for international GPS metric coordinates, this can go to the official website to see, the value range is 1-7
To: The type of coordinates to be converted to, can only be 5 or 6,5 for Baidu map coordinates, 6 for Baidu map metric coordinates (don't ask me what is the metric coordinates, I do not know ...)
Callback: Callback
Of course it's just a hypothesis.
3, register in CONVGPS callback, use the converted latitude and longitude to create a marker and place the center of the map on this latitude and longitude, that is, the same as the previous code
Note that the following code should not be used directly, just provide a code of thought, because I did not check the name of the function.
1Navigator.geolocation.getCurrentPosition (function(position) {2 3 //get HTML5 positioning results4 varx =Position.coords.longitude;5 vary =Position.coords.latitude;6 7 //as the result of HTML5 positioning is the international standard GPS, so from=1,to=58 //The following code is not actually so, here just provides a thought9Bmap.convgps (x, Y, 1, 5,function(convrst) {Ten varPoint =NewBmap.point (Convrst.x, convrst.y); One A //This part is the same as the code above. - varMarker =NewBmap.marker (point); - Map.addoverlay (marker); the Map.panto (point); - }) - -})
About Baidu Map JS API GetCurrentPosition Positioning is not accurate solution method