SITUATION:
I need to include a Google map in my Ionic app.
CARD SETTING:
To verify this, I followed these steps:
- Register Google Developer Console
- Enable JavaScript API Google Maps
- Get API key as browser key
Add a script to index.html:
<script src="http://maps.google.com/maps/api/js?key=MY_API_KEY&sensor=true"></script>
Create a div map and related css:
<div id="map" data-tap-disabled="true"></div> #map { width: 100%; height: 100%; }
Make a basemap in the user's geolocation center:
.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"); }); });
RELEASE:
It works fine, but that was for testing purposes in the browser. When I tested it in the application or in the emulator (Genymotion), the card does not even open. Of course, the reason may be simple: because I have a browser key.
But I tried other keys and did not open anyway.
Since the code is correct, the questions are:
- What type of Google Maps do I need to enable in order to have a Google map in my Ionic app that works great for Android and Ios?
Is the Google Maps JavaScript API selected correctly?
- What type of key should I get between the server key - browser key - android key - ios key? Does the browser key use for native applications?
Thanks!
source share