import React from 'react';
let key = 'XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX';
export default class Qq_map extends React.Component {
componentDidMount() {
this.initMap();
}
TMap = key => {
return new Promise(function(resolve, reject) {
window.init = function() {
resolve(qq);
};
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'http://map.qq.com/api/js?v=2.exp&callback=init&key=' + key;
script.onerror = reject;
document.head.appendChild(script);
});
};
initMap = () => {
let tarLat = 39.984120;
let tarLng = 116.307484;
this.TMap(key).then(qq => {
let myLatlng = new qq.maps.LatLng(tarLat, tarLng);
let myOptions = {
zoom: 16,
center: myLatlng,
mapTypeId: qq.maps.MapTypeId.ROADMAP,
};
this.map = new qq.maps.Map(document.getElementById('myMap'), myOptions);
let markerlast = new qq.maps.Marker({
position: myLatlng,
map: this.map,
});
});
};
render() {
return <div id="myMap" />;
}
}