ionic framework google map iphone 和 android 模拟器不工作
ionic framework google map iphone and android simulator not working
ionic 框架 google 地图在浏览器上运行,但在 iphone/android 模拟器上运行。
我尝试了所有 google api 服务器密钥、ios 密钥、android 密钥和从 google 控制台生成的浏览器密钥 api, 但在模拟器上仍然显示空白。
controller('MapCtrl', function($scope, $ionicLoading, $compile) {
function initialize() {
var myLatlng = new google.maps.LatLng(43.07493,-89.381388);
var mapOptions = {
center: myLatlng,
zoom: 16,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"),
mapOptions);
//Marker + infowindow + angularjs compiled ng-click
var contentString = "<div><a ng-click='clickTest()'>Click me!</a></div>";
var compiled = $compile(contentString)($scope);
var infowindow = new google.maps.InfoWindow({
content: compiled[0]
});
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Uluru (Ayers Rock)'
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
google.maps.event.addDomListener(window, 'resize',function(){
var center = map.getCenter();
google.maps.event.trigger(map, "resize");
map.setCenter(center);
})
$scope.map = map;
}
google.maps.event.addDomListener(window, 'load', initialize);
$scope.centerOnMe = function() {
if(!$scope.map) {
return;
}
$scope.loading = $ionicLoading.show({
content: 'Getting current location...',
showBackdrop: false
});
navigator.geolocation.getCurrentPosition(function(pos) {
$scope.map.setCenter(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));
$scope.loading.hide();
}, function(error) {
alert('Unable to get location: ' + error.message);
});
};
$scope.clickTest = function() {
alert('Example of infowindow with ng-click')
};
})
删除代码 google.maps.event.addDomListener(window, 'load', 初始化);并放入初始化();在函数 initialize() 之上。因为我的 google 地图不在第一个选项卡上,它在最后一个选项卡上。
ionic 框架 google 地图在浏览器上运行,但在 iphone/android 模拟器上运行。
我尝试了所有 google api 服务器密钥、ios 密钥、android 密钥和从 google 控制台生成的浏览器密钥 api, 但在模拟器上仍然显示空白。
controller('MapCtrl', function($scope, $ionicLoading, $compile) {
function initialize() {
var myLatlng = new google.maps.LatLng(43.07493,-89.381388);
var mapOptions = {
center: myLatlng,
zoom: 16,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"),
mapOptions);
//Marker + infowindow + angularjs compiled ng-click
var contentString = "<div><a ng-click='clickTest()'>Click me!</a></div>";
var compiled = $compile(contentString)($scope);
var infowindow = new google.maps.InfoWindow({
content: compiled[0]
});
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Uluru (Ayers Rock)'
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
google.maps.event.addDomListener(window, 'resize',function(){
var center = map.getCenter();
google.maps.event.trigger(map, "resize");
map.setCenter(center);
})
$scope.map = map;
}
google.maps.event.addDomListener(window, 'load', initialize);
$scope.centerOnMe = function() {
if(!$scope.map) {
return;
}
$scope.loading = $ionicLoading.show({
content: 'Getting current location...',
showBackdrop: false
});
navigator.geolocation.getCurrentPosition(function(pos) {
$scope.map.setCenter(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));
$scope.loading.hide();
}, function(error) {
alert('Unable to get location: ' + error.message);
});
};
$scope.clickTest = function() {
alert('Example of infowindow with ng-click')
};
})
删除代码 google.maps.event.addDomListener(window, 'load', 初始化);并放入初始化();在函数 initialize() 之上。因为我的 google 地图不在第一个选项卡上,它在最后一个选项卡上。