Google Map Directive in Ionic

Size
3,479 Kb
Views
42,504

How do I make an google map directive in ionic?

Using two tabs with a google maps directive in each one and as soon as the two maps are rendered in the page. What is a google map directive in ionic? How do you make a google map directive in ionic? This script and codes were developed by Aaron K Saunders on 25 September 2022, Sunday.

Google Map Directive in Ionic Previews

Google Map Directive in Ionic - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Google Map Directive in Ionic</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <html ng-app="ionicApp"> <head> <meta charset="utf-8"> <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> <title>Tabs Example</title> <link href="https://code.ionicframework.com/nightly/css/ionic.min.css" rel="stylesheet"> <link href='https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,800,600,300,700' rel='stylesheet' type='text/css'> <script src="https://code.ionicframework.com/nightly/js/ionic.bundle.min.js"></script> <script src="https://maps.googleapis.com/maps/api/js?libraries=weather,visualization&sensor=false&language=en&v=3.14"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script> <script src="https://rawgithub.com/nlaplante/angular-google-maps/master/dist/angular-google-maps.min.js"></script> </head> <body> <ion-nav-bar animation="nav-title-slide-ios7" class="bar-positive"> <ion-nav-back-button class="button-icon ion-arrow-left-c"> </ion-nav-back-button> </ion-nav-bar> <ion-nav-view animation="slide-left-right"></ion-nav-view> <script id="tabs.html" type="text/ng-template"> <ion-tabs tabs-type="tabs-icon-top" tabs-style="tabs-positive"> <ion-tab title="MAP ONE" icon="ion-home" href="#/tab/home"> <ion-nav-view name="home-tab"></ion-nav-view> </ion-tab> <ion-tab title="MAP TWO" icon="ion-ios7-information" href="#/tab/about" > <ion-nav-view name="about-tab"></ion-nav-view> </ion-tab> </ion-tabs> </script> <script id="home.html" type="text/ng-template"> <ion-view title="MAP ONE" ng-if="onTabOne" > <ion-content has-header="true" has-tabs="true" padding="true"> <button ng-click="hideMap = !hideMap">HIDE MAP</button> <button ng-click="addMarker()">ADD MARKER</button> <google-map center="center" zoom="zoom" > <markers models='markers' coords="'self'" icon='map.marker.icon' click="'onClicked'"> <windows show="'showWindow'" closeClick="'closeClick'" ng-cloak> <p ng-non-bindable>This is an info window at {{ latitude | number:4 }}, {{ longitude | number:4 }}!</p> <p class="muted" ng-non-bindable>{{title}}!</p> </windows> </markers> </google-map> </ion-nav-view > </ion-view> </script> <script id="about.html" type="text/ng-template"> <ion-view title="MAP TWO" ng-if="onTabTwo"> <ion-content has-header="true" has-tabs="true" padding="true"> <div > <google-map id='map2' center="center" zoom="zoom"> <markers models='markers' coords="'self'" icon='map.marker.icon'> <windows show="'showWindow'" closeClick="'closeClick'" ng-cloak> <p ng-non-bindable>This is an info window at {{ latitude | number:4 }}, {{ longitude | number:4 }}!</p> <p class="muted">My marker will stay open when the window is popped up!</p> </windows> </markers> </google-map> </div> </ion-content> </ion-view> </script> </body>
</html> <script src="js/index.js"></script>
</body>
</html>

Google Map Directive in Ionic - Script Codes CSS Codes

.angular-google-map-container { height: 400px; }
.marker-labels { color: red; background-color: white; font-family: "Lucida Grande", "Arial", sans-serif; font-size: 10px; font-weight: bold; text-align: center; width: 40px; border: 1px solid black; white-space: nowrap;
}
.angular-google-map { display: block; }

Google Map Directive in Ionic - Script Codes JS Codes

angular.module('ionicApp', ['ionic','google-maps'])
.config(function($stateProvider, $urlRouterProvider) { $stateProvider .state('tabs', { url: "/tab", abstract: true, templateUrl: "tabs.html" }) .state('tabs.home', { url: "/home", views: { 'home-tab': { templateUrl: "home.html", controller: 'HomeTabCtrl' } } }) .state('tabs.about', { url: "/about", views: { 'about-tab': { templateUrl: "about.html", controller: 'AboutTabCtrl' } } }); $urlRouterProvider.otherwise("/tab/home");
})
.controller('AboutTabCtrl', function($scope,$log) { $scope.onTabTwo = true; $scope.onTabOne = false; angular.extend($scope, { center: { latitude: 45, longitude: -73 }, markers: [], zoom: 8 }); $scope.map = {};
})
.controller('HomeTabCtrl', function($scope,$log, $timeout) { angular.extend($scope, { center: { latitude: 38.89, longitude: -77.13, }, markers: [{ latitude: 38.89, longitude: -77.00, title: 'Marker 2' }], zoom:8 }); $scope.map = { }; $scope.onTabTwo = false; $scope.onTabOne = true; google.maps.visualRefresh = true; var onMarkerClicked = function (marker) { debugger; marker.showWindow = true; //window.alert("Marker: lat: " + marker.latitude + ", lon: " + marker.longitude + " clicked!!") }; $scope.addMarker = function() { var m = { latitude: 38.89, longitude: -77.03, title: 'm ' + new Date(), /* closeClick : function () { m.showWindow = false; $scope.$apply(); }, onClicked : function () { onMarkerClicked(m); }*/ }; $scope.markers.push(m); $log.log('$scope.markers ' + $scope.markers); alert('added'); };
});
Google Map Directive in Ionic - Script Codes
Google Map Directive in Ionic - Script Codes
Home Page Home
Developer Aaron K Saunders
Username aaronksaunders
Uploaded September 25, 2022
Rating 3
Size 3,479 Kb
Views 42,504
Do you need developer help for Google Map Directive in Ionic?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Aaron K Saunders (aaronksaunders) Script Codes
Create amazing art & images with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!