我正在尝试显示附近的学校,但是我无法加载地图,也无法在地图上放置标记。我能够根据其纬度和较长的“ console.log(“学校:” + place.geometry.location);“对所有学校进行日志记录。可以,但是不会将其放置在地图中/不会显示所有学校的标记...
这是html
<!-- Map -->
<div class="row">
<ng-map id="map"></ng-map>
</div>
这是JavaScript代码
angular.module('breazehomeDesktop').controller('LocalScoopCtrl', function($scope, $http, NgMap, Hazard, BASE_URL, NWS) {
// initialize the map
var map;
NgMap.getMap().then(function(map) {
//$scope.map = map;
var center = new google.maps.LatLng(25.727542, -80.238216);
map = new google.maps.Map(document.getElementById('map'), {
center: center,
zoom:13
});
var service = new google.maps.places.PlacesService(map);
service.nearbySearch({
location: center,
radius: 8000,
types:['school']
}, callback);
});
function callback (results,status) {
if(status === google.maps.places.PlacesServiceStatus.OK){
for(var i=0; i < results.length; i++){
console.log("Sucessfull google places api call");
createMarker(results[i]);
}
}else{
console.log("Error connecting to the google places api");
}
}
function createMarker(place) {
console.log("School: "+place.geometry.location);
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location
});
};
});