Created
October 2, 2020 22:25
-
-
Save hemangsk/830ec1a27d960d250fa37ab0814c2a87 to your computer and use it in GitHub Desktop.
capacitor-googlemaps-native Android component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ion-header [translucent]="true"> | |
<ion-toolbar> | |
<ion-title> | |
Android | |
</ion-title> | |
</ion-toolbar> | |
</ion-header> | |
<ion-content [fullscreen]="true"> | |
<ion-header collapse="condense"> | |
<ion-toolbar> | |
<ion-title size="large">Android</ion-title> | |
</ion-toolbar> | |
</ion-header> | |
<div id="map" #map></div> | |
</ion-content> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#map { | |
margin: 2em 1em; | |
height: 250px; | |
border: 1px solid black; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, ViewChild, ElementRef } from '@angular/core'; | |
import { Plugins } from '@capacitor/core'; | |
const { CapacitorGoogleMaps, Device } = Plugins; | |
@Component({ | |
selector: 'app-android-gmaps', | |
templateUrl: 'android-gmaps.page.html', | |
styleUrls: ['android-gmaps.page.scss'] | |
}) | |
export class AndroidGmapsPage { | |
@ViewChild('map', {static: false}) mapView: ElementRef; | |
capacitorGoogleMapsPlugin = CapacitorGoogleMaps; | |
constructor() { | |
} | |
async ngOnInit() { | |
} | |
async ionViewDidEnter() { | |
const boundingRect = this.mapView.nativeElement.getBoundingClientRect() as DOMRect; | |
this.capacitorGoogleMapsPlugin.create({ | |
width: Math.round(boundingRect.width), | |
height: Math.round(boundingRect.height), | |
x: Math.round(boundingRect.x), | |
y: Math.round(boundingRect.y), | |
latitude: -33.86, | |
longitude: 151.20, | |
zoom: 12, | |
}); | |
this.capacitorGoogleMapsPlugin.addListener('onMapReady', async () => { | |
this.capacitorGoogleMapsPlugin.addMarker({ | |
latitude: -33.86, | |
longitude: 151.20, | |
title: 'Custom Title', | |
snippet: 'Custom Snippet', | |
}); | |
this.capacitorGoogleMapsPlugin.setMapType({ | |
type: 'normal', | |
}); | |
}); | |
} | |
ionViewDidLeave() { | |
this.capacitorGoogleMapsPlugin.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment