I now do a project is angular, but I use the direct reference Baidu map method to introduce JS, write Html,js code, found, I went, the error, I initially thought is Baidu Map and angular conflict, and then I went to search Ah, Found angular also has a Baidu map plugin, but I used the error, the internet said to use the ANGULAR2 version to be compatible, but I will not download the 2 version, so I gave up, and then, I went to solve my first mistake, found that the Madeleine I was stupid force, First of all, Baidu map How to use it, very simple, on the code
First to introduce JS
<script type= "Text/javascript" src= ' http://api.map.baidu.com/api?v=2.0&ak= your secret key ' ></script>
Explain, secret key you can in Baidu Map API website Application ha
Then HTML
<div id= ' map ' ></div>
And then to the direct JS code, in fact, all of these APIs have all, but I still posted it
Var map = new bmap. map ("map"); // create a Map instance
Map. CenterAndZoom (new BMap. Point (115.864528, 28.687675), 11); // initialize the map, set the center coordinates and map levels
Map. AddControl (new BMap. MapTypeControl ()); // add map type control
Map. SetCurrentCity (" nanchang "); // setting the city shown on the map is mandatory
Map. EnableScrollWheelZoom (true); // turn on the mouse wheel to zoom
These JS code I started with the body behind, but the error, what is wrong, paste
Getscript?v=2.0&ak= your secret key &services=&t=20160928173929:1 uncaught.
Typeerror:cannot Read property ' FC ' of undefined
Well, it's a mistake, I'm going, the wrong solution is simple.
is to put the JS code in your map with the div below, paste code
< div id = 'map' > < / div >
< script type = "text/javascript" >
Var map = new bmap. map ("map"); // create a Map instance
Map. CenterAndZoom (new BMap. Point (115.864528, 28.687675), 11); // initialize the map, set the center coordinates and map levels
Map. AddControl (new BMap. MapTypeControl ()); // add map type control
Map. SetCurrentCity (" nanchang "); // setting the city shown on the map is mandatory
Map. EnableScrollWheelZoom (true); // turn on the mouse wheel to zoom
< / script >
In this way, there is no error, the map is also perfect present, I go, in the final analysis or I was too stupid, I thought it was really angular conflict, and then on a think, impossible ah, and then did not go to the angular of that Baidu plug-in where the specialized research ...
Thank you for reading, I hope to help you, thank you for your support for this site!