Hi.
Now I’m studying ionic.And i want my project to show the location of the place. Along with the user’s current location as well But now I have a problem where I can not display GPS position.
$scope.loca = function (nameG, lat, lng) {
window.localStorage.setItem("nameGarage", nameG);
window.localStorage.setItem("lat", lat);
window.localStorage.setItem("log", lng);
}
function initialize() {
var myLatlng = new google.maps.LatLng(7.869238,98.374218);
var nameGarage = window.localStorage.getItem("nameGarage");
var lat = window.localStorage.getItem("lat");
var long = window.localStorage.getItem("log");
var locaGarage = new google.maps.LatLng(lat,long);
var mapOptions = {
center: locaGarage,
zoom: 15,
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()'>"+nameGarage+"</a></div>";
var compiled = $compile(contentString)($scope);
var infowindow = new google.maps.InfoWindow({
content: compiled[0]
});
var marker = new google.maps.Marker({
position: locaGarage,
map: map,
title: ''
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
$scope.map = map;
}
google.maps.event.addDomListener(window, 'load', initialize);
$scope.centerOnMe = function() {
if(!$scope.map) {
return;
}
$scope.loading = function(){
$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')
};