0% found this document useful (0 votes)
33 views110 pages

Ionic Native Google Maps Plugin Guide

Uploaded by

Lewis Zap
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views110 pages

Ionic Native Google Maps Plugin Guide

Uploaded by

Lewis Zap
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

@ionic-native / google-maps

Cordova GoogleMaps plugin project

Masashi Katsumata
Ionic framework
@ionic-native/google-maps
● Embed native Google Maps view in your app

● One code for both Android, iOS and Browser (from v4.12.0)

● Easy to use

● Faster than Google Maps Javascript API v3

● Free to use. Apache License v2


・UI components
Yo ・View management
u ・TypeScript -> JS
this r cod
bro e ru ...etc
ws no
er
vie n
w

b e t ween
e
Bridg system
e
nativ ur code!
o
and y
@ionic-native/google-maps

Let’s see the


demo!
<b
utto
n io
n-b
utt
o
(HT n>
ML
) a p!
e M w)
l e
o og e vi
G ativ
(n
ap
The M
is
able
touch
The M
ap
is not
s i d e menu toucha
ble!
The
is
u c h able!!
to
Google Map View is under the browser!!
(and this is not a HTML element)

This is native
Google Maps
view, which is not
a HTML element.
u c h layer
to
e)
(nativ

Is this on map
or browser?

Pass
the touch event to
the map or browser
Hello world
API key

Create a project [Link]


API key

Create a project
[Link]
API key

Enable billing
You need to register your
payment way.

But don’t worry, you probably


won’t charge.
Because Google Maps Android
API and Google Maps SDK for
iOS are free.
(Except geocoding, StreetView)
Are Google Maps APIs free to use?
● Yes!!
"Google Maps Android API v2" and "Google Maps SDK for iOS" are free, and
unlimited usage (at this time)! Thus, this plugin is also free!

● But no!!
If you run your app on the browser platform, this plugin uses Google Maps
JavaScript API v3.

● Bonus: you can get $200 credit / month for other Maps APIs
(Google Directions API, Google Maps JavaScript API v3, and so on)
API key

Enable Google Maps APIs


API key

Enable Google Maps APIs

This
i
API s your
key

Restrict your key when


you release your app
API key Create project

Create a project
$> ionic start myApp sidemenu --type=angular
? Integrate your new app with Cordova to target native iOS and Android? YES

$> npm install @ionic-native/core

$> npm install @ionic-native/google-maps


API key Create project

Install cordova-plugin-googlemaps

$> ionic cordova plugin add cordova-plugin-googlemaps


API key Create project

Edit `confi[Link]`

<?xml version='1.0' encoding='utf-8'?>


<widget ...>

<preference
name="GOOGLE_MAPS_ANDROID_API_KEY" value="(api key)" />
<preference
name="GOOGLE_MAPS_IOS_API_KEY" value="(api key)" />

</widget>
API key Create project HTML & CSS

src/app/home/[Link]

<ion-content padding>
<h3>Ionic GoogleMaps Starter</h3>

<div id="map_canvas">
<button ion-button (click)="onButtonClick($event)">Start demo</button>
</div>

</ion-content> Ad
da
div
(m
ap
div
)
API key Create project HTML & CSS

src/pages/home/[Link]
Background styles become be transparent
#map_canvas { by the maps plugin mandatory!
height: 90%;
} You can set the background color through
[Link]()

100 x 100 pixels are minimum requirement


dimension.
API key Create project HTML & CSS Coding

src/app/home/[Link]
import { Component, OnInit } from '@angular/core';
import { Platform } from '@ionic/angular';
import { GoogleMaps, GoogleMap } from '@ionic-native/google-maps/ngx';

export class HomePage implements OnInit {

map: GoogleMap;

constructor(private platform:Platform) {}

async ngOnInit() {
// you need to wait `[Link]()`
await [Link](); Important!!!

await [Link]();
}
If you forget that …

ionViewDidLoad() is executed
(DOM elements are ready)

Then you get this error message

[Link]() is executed later


(the native plugins are ready to use)
API key Create project HTML & CSS Coding

src/app/home/[Link]
loadMap() {
// If you want to run your app
// on browser, insert this line.
[Link]({
'API_KEY_FOR_BROWSER_RELEASE': '',
'API_KEY_FOR_BROWSER_DEBUG':''
});

// Create a map
// after the view is ready
// and the native platform is ready.
[Link] = [Link]('map_canvas');

}
API key Create project HTML & CSS Coding Run it!

Run it!!
$> ionic cordova run android $> ionic cordova run browser -l
Marker

@ionic-native/google-maps
Add a marker
[Link]({
title: '@ionic-native/google-maps',
icon: 'blue',
animation: 'DROP',
position: {
lat: 43.0741904,
lng: -89.3809802
}
}).then((marker: Marker) => {

[Link]();

});
Add a marker from v4.8.2 -

let marker: Marker = [Link]({


title: '@ionic-native/google-maps',
icon: 'blue',
animation: 'DROP',
position: {
lat: 43.0741904,
lng: -89.3809802
}
});

[Link]();
icon property
[Link]({ color name : blue, red, green, yellow ....
title: '@ionic-native/google-maps', (157 color names are defined in this plugin)
icon: 'blue',
animation: 'DROP', rgb(), rgba() , hsl(), hsla(), #RGB, #RGBA
position: { :
./assets/[Link] (jpg, gif, and png) :
lat: 43.0741904,
lng: -89.3809802 http(s)://yourserver/[Link] :
}
}); cdvfile:// …. /[Link] :

data:image/png;base64,iVBORw0KGgo...CC :
:
icon property
let POINTS: BaseArrayClass<any> = new BaseArrayClass<any>([
{
position: {lat:41.79883, lng:140.75675},
iconData: "./assets/imgs/[Link]"
},
{
position: {lat:41.799240000000005, lng:140.75875000000002},
iconData: "[Link]
},
{
position: {lat:41.797650000000004, lng:140.75905},
iconData: {
url: "[Link]
size: { width: 24, height: 24}
}
},
{
position: {lat:41.79637, lng:140.76018000000002},
title: "4",
iconData: "blue"
},
{
position: {lat:41.79567, lng:140.75845},
title: "5",
iconData: "data:image/png;base64,iVBORw...CC"
}
]);
Marker events
● MARKER_CLICK

● MARKER_DRAG_START
● MARKER_DRAG
● MARKER_DRAG_END

● INFO_CLICK
● INFO_LONG_CLICK
● INFO_OPEN
● INFO_CLOSE
Add event listener
Listen the event only one time
[Link](GoogleMapsEvent.MARKER_CLICK).then();

// Alias method
[Link](GoogleMapsEvent.MARKER_CLICK).then();

Listen the event multiple times


[Link](GoogleMapsEvent.MARKER_CLICK).subscribe();

// Alias method
[Link](GoogleMapsEvent.MARKER_CLICK).subscribe();
Remove event listener
Listen the event only one time
// Remove particular event listener
[Link](GoogleMapsEvent.MARKER_CLICK, [Link]);

// Remove all event listeners for the MARKER_CLICK event


[Link](GoogleMapsEvent.MARKER_CLICK);

// Remove all event listeners of all events


[Link]();
Example
[Link]({
position: {
lat: 43.0741804,
lng: -89.381
},
title: "A",
disableAutoPan: true
}).then([Link]);

[Link]({
position: {
lat: 43.0741804,
lng: -89.382
},
title: "B",
disableAutoPan: true
}).then([Link]);

onMarkerAdded(marker: Marker) {
[Link](GoogleMapsEvent.MARKER_CLICK).then(() => {
alert("Marker" + [Link]() + " is clicked");
});
}
Polyline

@ionic-native/google-maps
Polyline
let AIR_PORTS = [
HND_AIR_PORT, HNL_AIR_PORT, SFO_AIR_PORT
];

[Link]({
points: AIR_PORTS, Click e
ve
color: '#AA00FF', (Becaus nt with LatL
e this ng
width: 10, plugin
calcula
geodesic: true, tes own
way)
clickable: true // clickable = false in default
}).then((polyline: Polyline) => {
[Link](GoogleMapsEvent.POLYLINE_CLICK).subscribe((params: any) => {
let position: LatLng = <LatLng>params[0];
[Link]({
position: position,
title: [Link](),
disableAutoPan: true
}).then((marker: Marker) => {
[Link]();
});
});
});
Polyline from v4.8.2 -
let AIR_PORTS = [
HND_AIR_PORT, HNL_AIR_PORT, SFO_AIR_PORT
];

let polyline: Polyline = [Link]({


points: AIR_PORTS,
color: '#AA00FF',
width: 10,
geodesic: true,
clickable: true // clickable = false in default
})

[Link](GoogleMapsEvent.POLYLINE_CLICK).subscribe((params: any) => {


let position: LatLng = <LatLng>params[0];
let marker: Marker = [Link]({
position: position,
title: [Link](),
disableAutoPan: true
});
[Link]();
});
Polygon

@ionic-native/google-maps
Polygon
let GORYOKAKU_POINTS: ILatLng[] = [
{lat: 41.79883, lng: 140.75675},
{lat: 41.799240000000005, lng: 140.75875000000002},
{lat: 41.797650000000004, lng: 140.75905},

{lat: 41.79909000000001, lng: 140.75465}
]; ng[]
s I LatL
pas
[Link]({ Just
'points':GORYOKAKU_POINTS,
'strokeColor' : '#AA00FF',
'fillColor' : '#00FFAA',
'strokeWidth': 10
}.then((polygon: Polygon) => {

...

});
Polygon from v4.8.2 -

let GORYOKAKU_POINTS: ILatLng[] = [


{lat: 41.79883, lng: 140.75675},
{lat: 41.799240000000005, lng: 140.75875000000002},
{lat: 41.797650000000004, lng: 140.75905},

{lat: 41.79909000000001, lng: 140.75465}
];

let polygon: Polygon = [Link]({


'points':GORYOKAKU_POINTS,
'strokeColor' : '#AA00FF',
'fillColor' : '#00FFAA',
'strokeWidth': 10
});
Circle

@ionic-native/google-maps
Circle
let center: ILatLng = {"lat": 32, "lng": -97};
let radius = 300; // radius (meter)

[Link]({
'center': center,
'radius': radius,
'strokeColor' : '#AA00FF',
'strokeWidth': 5,
'fillColor' : '#00880055'
}).then((circle: Circle) => {

[Link]('position_changed').subscribe((params: any) => {


let newValue: ILatLng = <ILatLng>params[1];

let newRadius: number = [Link](


center, newValue);

[Link](newRadius);
});
});
Circle from v4.8.2 -

let center: ILatLng = {"lat": 32, "lng": -97};


let radius = 300; // radius (meter)

let circle: Circle = [Link]({


'center': center,
'radius': radius,
'strokeColor' : '#AA00FF',
'strokeWidth': 5,
'fillColor' : '#00880055'
});

[Link]('position_changed').subscribe((params: any) => {


let newValue: ILatLng = <ILatLng>params[1];

let newRadius: number = [Link](


center, newValue);

[Link](newRadius);
});
GroundOverlay

@ionic-native/google-maps
GroundOverlay
[Link](GoogleMapsEvent.MAP_READY).then(() => {
return [Link]({
'url': 'assets/imgs/newark_nj_1922.jpg',
'bounds': bounds,
'opacity': 0.5,
'clickable': true // default = false
});
}).then((groundOverlay: GroundOverlay) => {

// Catch the GROUND_OVERLAY_CLICK event


[Link](GoogleMapsEvent.GROUND_OVERLAY_CLICK).subscribe(() => {
[Link]('assets/imgs/newark_nj_1922_2.jpg');
});

});
GroundOverlay from v4.8.2 -

let groundOverlay: GroundOverlay = [Link]({


'url': 'assets/imgs/newark_nj_1922.jpg',
'bounds': bounds,
'opacity': 0.5,
'clickable': true // default = false
});
});

// Catch the GROUND_OVERLAY_CLICK event


[Link](GoogleMapsEvent.GROUND_OVERLAY_CLICK).subscribe(() => {
[Link]('assets/imgs/newark_nj_1922_2.jpg');
});
TileOverlay

@ionic-native/google-maps
TileOverlay
You can
generat
e vario
us URL
[Link]({
getTile: (x: number, y: number, zoom: number) => {
return "[Link] +
zoom + "/" + x + "/" + y + ".jpg";
},

// draw the debug information on tiles


debug: false,

opacity: 1.0
});
TileOverlay from v4.8.2 -

let tileOverlay: TileOverlay = [Link]({


getTile: (x: number, y: number, zoom: number) => {
return "[Link] +
zoom + "/" + x + "/" + y + ".jpg";
},

// draw the debug information on tiles


debug: false,

opacity: 1.0
});
HtmlInfoWindow

@ionic-native/google-maps
HtmlInfoWindow(1)
let htmlInfoWindow = new HtmlInfoWindow();
let frame: HTMLElement = [Link]('div');
[Link] = [
'<h3>Hearst Castle</h3>',
'<img src="assets/imgs/hearst_castle.jpg">'
].join("");
[Link]("img")[0].addEventListener("click", () => {
[Link]('red');
});
[Link](frame, {width: "280px", height: "330px"});

[Link]({
position: {lat: 35.685208, lng: -121.168225},
draggable: true,
disableAutoPan: true
}).then((marker: Marker) => {
[Link](GoogleMapsEvent.MARKER_CLICK).subscribe(() => {
[Link](marker);
});
});
HtmlInfoWindow(2) Full source code

onMarkerClick(params: any[]) {
// Get a marker instance from the passed parameters
let marker: Marker = [Link]();

// Create a component
const compFactory = [Link](CustomTag);
let compRef: ComponentRef<CustomTag> =
[Link]([Link]);
[Link] = [Link]('myTitle');
[Link]([Link]);

let div = [Link]('div');


[Link]([Link]);

// Dynamic rendering
this._ngZone.run(() => {
[Link](div);
[Link](marker);
});
}
Marker cluster

@ionic-native/google-maps
MarkerCluster
[Link]({
markers: data,
icons: [
{
min: 3, max: 9,
url: "./assets/markercluster/[Link]",
label: { color: "white" }
},
{
min: 10,
url: "./assets/markercluster/[Link]",
label: { color: "white" }
}
]
}).then((markerCluster: MarkerCluster) => {

[Link](GoogleMapsEvent.MARKER_CLICK).subscribe((params) => {
let marker: Marker = params[1];
[Link]([Link]("name"));
[Link]([Link]("address"));
[Link]();
});

});
MarkerCluster from v4.8.2 -

let markerCluster: MarkerCluster = [Link]({


markers: data,
icons: [
{
min: 3, max: 9,
url: "./assets/markercluster/[Link]",
label: { color: "white" }
},
{
min: 10,
url: "./assets/markercluster/[Link]",
label: { color: "white" }
}
]
});

[Link](GoogleMapsEvent.MARKER_CLICK).subscribe((params) => {

let marker: Marker = params[1];


[Link]([Link]("name"));
[Link]([Link]("address"));
[Link]();

});
Geocoding

@ionic-native/google-maps
Geocoding
ess
// Address -> latitude,longitude addr
one
g for
[Link]({ odin
Geoc
"address": this.search_address
})
.then((results: GeocoderResult[]) => {
[Link](results);

return [Link]({
'position': results[0].position,
'title': [Link](results[0].position)
})
})
.then(...)
Batch geocoding rray
n s as a
[Link]({ tio
loca
Pass
// US Capital cities
"address": [
"Montgomery, AL, USA", "Juneau, AK, USA", ...
"Madison, WI, USA", "Cheyenne, Wyoming, USA"
]
})
.then((mvcArray: BaseArrayClass<GeocoderResult[]>) => {
Get
}); a
then mvc ar
r
noti `finish ay firs
fied ` ev t
. ent ,
is

Just
1.9 s
ec!
BaseClass

@ionic-native/google-maps
All classes extend Base class

GroundOverlay TileOverlay MarkerCluster

Circle Polyline Polygon

BaseArrayClass Map Marker

BaseClass
BaseClass
● set()

● get()

● bindTo()

● trigger()

● on() / addEventListener()

● one() / addEventListenerOnce()

● off()

● empty()

● destroy()
set() and get() [Link](key, value, noNotify?)
[Link](key)

let myObj: BaseClass = new BaseClass();

[Link]("hello", "world");
"Hel
lo_c
[Link]([Link]("hello")); hang
ed"
even
t oc
curs
(key)_changed event
let myObj: BaseClass = new BaseClass();

[Link]("hello_changed").subscribe((params) =>an{ged
h
[Link](params); o_c
hell
});

[Link]("hello", "world");
[Link]("hello", "world2"); hello_c
hange
d
Status change event anged
_ch
ition
pos

[Link](...);

title_changed

[Link]("....");
Own property
[Link]({
position: { lat: 43.0741704, lng: -89.3809802},
count: 0
})
.then((marker: Marker) => {
[Link](GoogleMapsEvent.MARKER_CLICK).subscribe(() => {
[Link]("count", [Link]("count") + 1);
});

[Link]("count_changed").subscribe((params: []) => {


let oldValue = params[0];
let newValue = params[1];
let key = params[2];
[Link]("'" + key + "' is changed from '" +
oldValue + "' to '" + newValue + "'");
});

});
Own property from v4.8.2 -

let marker: Marker = [Link]({


position: { lat: 43.0741704, lng: -89.3809802},
count: 0
});
[Link](GoogleMapsEvent.MARKER_CLICK).subscribe(() => {
[Link]("count", [Link]("count") + 1);
});

[Link]("count_changed").subscribe((params: []) => {


let oldValue = params[0];
let newValue = params[1];
let key = params[2];
[Link]("'" + key + "' is changed from '" +
oldValue + "' to '" + newValue + "'");
});
noNotify option
let myObj: BaseClass = new BaseClass();

[Link]("hello_changed").subscribe((params) => { DO N
OT
[Link](params); OCC
UR
}); hello_changed

[Link]("hello", "world", true);


bindTo() [Link](targetKey, dest, destKey?, noNotify?)

let objA: BaseClass = new BaseClass();


let objB: BaseClass = new BaseClass();

[Link]("hello", objB, "world");

[Link]("hello", "こんにちは");
[Link]("world");

objA objB

hello world

"こんにちは" "こんにちは"
bindTo()
[Link]({
position: {lat: 43.0741704, lng: -89.3809802},
draggable: true
})
.then((marker: Marker) => {
[Link]({
center: [Link](),
radius: 10,
fillColor: "rgba(0, 0, 255, 0.5)",
strokeColor: "rgba(0, 0, 255, 0.75)",
strokeWidth: 1
}).then((circle: Circle) => {
[Link]("position", circle, "center");
});
});
bindTo() from v4.8.2 -

let marker: Marker = [Link]({


position: {lat: 43.0741704, lng: -89.3809802},
draggable: true
});
let circle: Circle = [Link]({
center: [Link](),
radius: 10,
fillColor: "rgba(0, 0, 255, 0.5)",
strokeColor: "rgba(0, 0, 255, 0.75)",
strokeWidth: 1
});

[Link]("position", circle, "center");


trigger() [Link](eventName, args?...)

createMarkers() {
let bounds = [Link]();
let sw = [Link], ne = [Link];
let diffY = ([Link] - [Link]), diffX = ([Link] - [Link]);
for (let i = 0; i < 10; i++) {
[Link]({
'position': {
'lat': [Link] + diffY * [Link](),
'lng': [Link] + diffX * [Link]()
}
}).then((marker:Marker) => {
[Link]('animate').subscribe((params: []) => {
let animation: string = params[0];
[Link](animation);
});
});
}
}
onButtonClick() {
let btnTxt: string = [Link];
[Link]("animate", btnTxt);
}
Deep understanding
Internal command queue
Cordova executes all methods in asynchronously!
[Link]({ .then((marker:Marker) =>
… {
})
});

exec("Map", "loadPlugin",
"Marker");

[Link]()
(native code)
What would be occurred like this code?
[Link]();

for (let i = 0; i < [Link]; i++) {

[Link]({
position: positions[i]
}).then((marker: Marker) => {

[Link](marker);

});

}
[Link]() is slow...
Correct way:
[Link]();
[Link]().then(() => {
for (let i = 0; i < [Link]; i++) { ….
});
[Link]({
position: positions[i]
}).then((marker: Marker) => {

[Link](marker);

});

}
Don’t worry, this plugin handles correctly!
[Link]();

for (let i = 0; i < [Link]; i++) {

[Link]({
position: positions[i]
}).then((marker: Marker) => {

[Link](marker);

});

}
Because this plugin has own command queue!
Execute method in synchronous
[Link]()
(Stop all other methods)

addMarker() addMarker() addMarker() addMarker() addMarker()

addMarker() addMarker() addMarker() addMarker() addMarker()

addMarker() addMarker() addMarker() addMarker() addMarker()

addMarker() addMarker() addMarker() addMarker() addMarker()

Execute 10 methods in parallel at a once


Limit 10 is problem sometimes...

Sorry, there is no solution currently.


synchronous methods
● [Link]() ● [Link]()
● [Link]() ● [Link]()
● [Link]() ● [Link]()
● [Link]() ● [Link]()
● [Link]() ● [Link]()
● [Link]() ● [Link]()
● [Link]()
● [Link]()
● [Link]()
● [Link]()
@ionic-native/google-maps
version 4.8.2

Breaking changes are introduced


You
Add new methods: Used be ... ca
this n still
synt u
ax c se
[Link]({ ode
position: {lat: …, lng: …},
● [Link]() title: "Hello world"
}).then((marker:Marker) => {
● [Link]() [Link]();
● [Link]() });
● [Link]()
● [Link]() from v4.8.2 -
● [Link]() let marker:Marker = [Link]({
● [Link]() position: {lat: …, lng: …},
title: "Hello world"
});

[Link]();
MAP_READY event
Used be ...

[Link] = [Link]('map_canvas');
[Link](GoogleMapsEvent.MAP_READY).then(() => {
[Link]({
position: {lat: …, lng: …},
title: "Hello world"
});
});
from v4.8.2 -

[Link] = [Link]('map_canvas');

let marker:Marker = [Link]({


position: {lat: …, lng: …},
title: "Hello world"
});
However, if you use [Link]()...
[Link] = [Link]('map_canvas');

let visibleRegion: VisibleRegion = [Link]();

[Link](visibleRegion); // == null

You still have to need to wait


MAP_READY event for this case!
StreetView panorama
class StreetViewPage {
let panorama: StreetViewPanorama;

ionViewDidLoad() {
[Link]();
}

loadPanorama() {

// Create a map after the view is loaded.


// (platform is already ready in [Link])
[Link] = [Link]('pano_canvas', {
camera: {
target: {lat: 42.345573, lng: -71.098326}
}
});

}
}
BaseArrayClass

@ionic-native/google-maps
BaseArrayClass
● map() ● indexOf() ● insertAt()

● mapAsync() ● empty() ● getArray()

● forEach() ● push() ● getAt()

● forEachAsync() ● pop() ● setAt()

● filter() ● removeAt()

● filterAsync() ● getLength()

● reverse()

● sort()
forEach() [Link](fn)

0 1 2 3 4
forEach() [Link](fn)

let baseArray: BaseArrayClass<ILatLng> = new BaseArrayClass(positions);

[Link]((position: ILatLng, idx: number) => {

[Link]({
position: position
}).then((marker: Marker) => {
[Link](marker);
});

});
forEachAsync() [Link](fn).then()

Async task
(i.e. setTimeout())
0 1 2 3 4
forEachAsync() [Link](fn).then()

let baseArray: BaseArrayClass<ILatLng> = new BaseArrayClass(positions);

[Link]((position: ILatLng, next:() => void) => {

[Link]({
position: position
}).then((marker: Marker) => {
[Link](marker);
next();
});

}.then(() => {
[Link]('finish!');
});
map() [Link](fn)

0 1 2 3 4

a b c d e

a b c d e
map() [Link](fn)

let baseArray: BaseArrayClass<Marker> = new BaseArrayClass([Link]);

let titles: [] = [Link]((marker: Marker, idx: number) => {

return [Link]();

});
mapAsync() [Link](fn).then()

0 1 2 3 4 Async task
(i.e. setTimeout())

a b c d e

a b c d e
mapAsync() [Link](fn).then()

let baseArray: BaseArrayClass<ILatLng> = new BaseArrayClass(positions);

[Link]((position: ILatLng, next: (result: any) => void) => {

[Link]({
position: position
}).then(next);

}).then(markers: Marker[]) => {


[Link]('finish!');
});
filter() [Link](fn)

0 1 2 3 4

true false true false true

a c e
filter() [Link](fn)

let baseArray: BaseArrayClass<Marker> = new BaseArrayClass([Link]);

let matchedMarkers: [] = [Link]((marker: Marker, idx: number) => {

return [Link]('category') === 'restaurant';

});
filterAsync() [Link](fn).then()

0 1 2 3 4 Async task
(i.e. setTimeout())

true false true false true

a c e
filterAsync() [Link](fn).then()

let baseArray: BaseArrayClass<Marker> = new BaseArrayClass([Link]);

[Link]((marker: Marker, next: (result: boolean) => void) => {

// i.e. Get data from remote database


http_request
.get('[Link] {id: [Link]('dbId')})
.then((locationData: object) => {

// detect later Asynchronous


process
next([Link] === 'restaurant');
});

}).then(matchedMarkers: Marker[]) => {


[Link]('finish');
});
push(), pop()
let baseArray: BaseArrayClass = new BaseArrayClass();

at event
insert_
[Link]('a');

[Link]('b');

[Link]('c');
remove_at event
[Link]();

[Link]();

[Link]();
BaseArrayClass example
let points: ILatLng[] = [
{lat: 33.91636924837674, lng: -118.39605331420898},
{lat: 33.90205144970967, lng: -118.39639663696288},
{lat: 33.90190897196702, lng: -118.37905883789062},
{lat: 33.89471353635718, lng: -118.3787155151367}
];

[Link] = [Link]('map_canvas', {
camera: {
target: points
}
});

[Link](GoogleMapsEvent.MAP_READY).then(() => {
return [Link]({
points: points
});
})

//continue to next page...


BaseArrayClass example
.then((polyline: Polyline) => {
let baseArray: BaseArrayClass<ILatLng> = [Link](); [Link]() returns
BaseArrayClass
[Link]((point: ILatLng, next: Function) => {
[Link]({
position: point,
draggable: true
}).then(next);
}, (markers: Marker[]) => {
[Link]((marker: Marker, idx: number) => {
[Link]('position_changed').subscribe((params: []) => {
[Link](idx, params[1]);
});
});

// trigger the position_changed event for the first calculation. nce


e d ista dragged
e th rs are
markers[0].trigger('position_changed', null, markers[0].getPosition());
ulat e
});
Calc ny mark
[Link]('set_at', () => { e n a
wh
this._ngZone.run(() => {
let distanceMeter: number = [Link](baseArray);
[Link] = (distanceMeter * 0.000621371192).toFixed(2) + " miles";
});
});
});
BaseArrayClass example
KML Overlay

@ionic-native/google-maps
KML overlay
[Link] = [Link]({
content: 'Please wait...'
});
[Link]();

[Link]({
url: "assets/kmloverlay/[Link]"
}).then((kmlOverlay: KmlOverlay) => { Fits cam
era
[Link](); to view
kml
overall
[Link](kmlOverlay);

[Link]([Link]());

// You can get additional information


[Link](GoogleMapsEvent.KML_CLICK).subscribe((params: any) => {
let overlay: Polygon = params[0]; // depends on overlay
let latLng: ILatLng = params[1];
[Link](overlay, latLng);
});

});
LocationService

@ionic-native/google-maps
LocationService
let option: MyLocationOptions = {
// true: use GPS as much as possible (use battery usage alot)
//
// false: use network location or lastKnownLocation
// (save battery usage)
enableHighAccuracy: true
};

[Link](option).then((location: MyLocation) => {


[Link] = [Link]({
'camera': [Link],
'zoom': 16
});

...
}).catch((error: any) => {
// Can not get location, permission refused, and so on...
[Link](error);
});
Good example projects

How to use this plugin in real project


Main page + detail page

Special thanks for battika


Use two maps in two pages
[Link]

There is a map and “Open Second Page” button in [Link].


If you tap on the button, open a detail page using
[Link](SecondPage,{},{animate:false});

In this case, ionic keeps the first page but css visibility = hidden.
The maps plugin can detect this particular case, and detach the main
page map automatically.
Then create another map for detail page.

After closing the second page, there is no more div element for the
second map. So the maps plugin destroys the second map automatically.

Then the maps plugin attaches the map view to browser automatically,
when the main page becomes visibility = visible.
Plugin repository
[Link]
cordova-plugin-googlemaps
Cordova GoogleMaps plugin
author Official documents
[Link]
& ative-google-maps/blob/master/docu
ments/[Link]
Google Developers Expert of
Google Maps API Code repository
[Link]
Masashi Katsumata googlemaps-quickdemo

You might also like