Hello
I have implemeted geolocations and dynamically added location marks by getting data from server. It is runny correclty when I put the <div id="map"></div>
in index.html. But when I tried it using ng-view its not loading the map and no error is there in console also.
function initialize() {
// Show Loader
//$scope.loading = $ionicLoading.show({
//content: 'Getting current location...',
//showBackdrop: false
//});
// Get Geolocation
var city_name;
navigator.geolocation.getCurrentPosition(function(pos) {
$scope.map.setCenter(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));
//$scope.loading.hide();
var latlng = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude);
var geocoder;
geocoder = new google.maps.Geocoder();
geocoder.geocode({'latLng': latlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
for (var i=0; i<results[0].address_components.length; i++) {
for (var b=0;b<results[0].address_components[i].types.length;b++) {
if (results[0].address_components[i].types[b] == "administrative_area_level_1") {
city= results[0].address_components[i];
break;
}
}
}
console.log(city.long_name)
city_name = city.long_name;
} else {
console.log("No results found");
}
} else {
console.log("Geocoder failed due to: " + status);
}
});
}, function(error) {
alert('Unable to get location: ' + error.message);
});
// Initialize Map
var mapOptions = {
center: new google.maps.LatLng(43.07493,-89.381388),
zoom: 16,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"),
mapOptions);
// Get Data for marker from http(json) for markers
var getProduct = "http://www.test.com/"; //dumy domain
$http({method: 'GET', url: getProduct}).success(function(data)
{
$scope.products = data.products;
console.log(data.products.length);
var marker, i;
for (i = 0; i < data.products.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(data.products[i].latitude, data.products[i].longitude),
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
marker.setMap(map);
});
// Stop the side bar from dragging when mousedown/tapdown on the map
google.maps.event.addDomListener(document.getElementById('map'), 'mousedown', function(e) {
e.preventDefault();
return false;
});
$scope.map = map;
}
google.maps.event.addDomListener(window, 'load', initialize);
Main problem mine is that I am not able to load the map in ng-view
This example runs well till I switch to ng-view.
https://github.com/driftyco/ionic/tree/master/examples/starters/map
Thanks
Gaurav