This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import coordtransform from "coordtransform"; | |
mapboxgl.accessToken = '<your mapbox access token>'; | |
let exampleMap; | |
// CHANGE WITH COORDINATES FROM HERE http://api.map.baidu.com/lbsapi/getpoint/ | |
const bd09Coords = [113.341334, 23.193119]; | |
function renderMap() { | |
if (exampleMap) exampleMap.remove(); | |
// this is where conversion happens | |
const gcj02 = coordtransform.bd09togcj02(bd09Coords[0], bd09Coords[1]); | |
console.log('GCJ-02: ', gcj02); | |
const wgs84Coordinates = coordtransform.gcj02towgs84(gcj02[0], gcj02[1]); | |
console.log('WGS-84: ', wgs84Coordinates); | |
// don't forget to add <div id='mapbox-map-id' style='width: 100%; height: 300px;'></div> | |
// somewhere in your html | |
exampleMap = new mapboxgl.Map({ | |
container: 'mapbox-map-id', | |
style: 'mapbox://styles/mapbox/streets-zh-v1', | |
zoom: 15, | |
center: wgs84Coordinates | |
}); | |
exampleMap.addControl(new window.mapboxgl.NavigationControl()); | |
new window.mapboxgl.Marker().setLngLat(wgs84Coordinates).addTo(exampleMap); | |
} | |
renderMap(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment