THE SITUATION:
I need to include a Google map inside my Ionic app.
SETTING UP THE MAP:
In order to test it I have done the following steps:
Add the script to index.html:
<script src="http://maps.google.com/maps/api/js?key=MY_API_KEY&sensor=true"></script>
Create a map div and related css:
<div id="map" data-tap-disabled="true"></div>
#map {
width: 100%;
height: 100%;
}
Make a basic map centered in the geolocation of the user:
.controller('MapCtrl', function($scope, $state, $cordovaGeolocation) {
var options = {timeout: 10000, enableHighAccuracy: true};
$cordovaGeolocation.getCurrentPosition(options).then(function(position){
var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
var mapOptions = {
center: latLng,
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
$scope.map = new google.maps.Map(document.getElementById("map"), mapOptions);
}, function(error){
console.log("Could not get location");
});
});
THE ISSUE:
It is working fine, but this was for test purpose in the browser. When i have tested it in the app or in the emulator (Genymotion) the map is not even opening. Of course the reason it may be simple: because i have a browser key.
But i have tried other keys and is not opening anyway.
Since the code is correct, the questions are:
Is Google Maps JavaScript API the correct choice?
Thank you!!
I have found a solution using angular-google-maps.
Following the basic steps in the documentation is enough to set it up. It works in a browser as an angular app and also in a phone as a Ionic hybrid app.
I have the same sample code with you, and face the same problem in Genymotion. I solve the problem by adjusting some Genymotion developer setting .
Dev Setting -> Allow mock locations checked Allow mock locations
Make sure the GPS is on . Set GPS on
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With