Starwave Starwave - 26 days ago 8
TypeScript Question

Nativescript: is it possible to access android sdk function/class through typescript?

Let's say I have this main component:

import { Component } from "@angular/core";

@Component({
selector: "my-app",
templateUrl: "./layouts/main-layout.html"
})
export class AppComponent {

constructor(

){}

ngAfterViewInit() {
//console.log( com.google.android.gms.maps.CameraUpdateFactory );
}

}


How can I call the commented-out function, right there in app.component.ts?

Because it gives me
"com" not found
error.

I have added
dependencies { compile 'com.google.android.gms:play-services-maps:9.8.0' }
in
App_Resources/Android/app.gradle
file.

I have also checked how
nativescript-google-maps-sdk
plugin does it. It seems it does it the same way - it has its' own
nativescript-google-maps-sdk/platforms/android/include.gradle
file, where it also defines the google play service maps from local android sdk, and in
nativescript-google-maps-sdk/map-view.android.js
I see it is using such a command without problem:

var cameraUpdate = com.google.android.gms.maps.CameraUpdateFactory.newCameraPosition( cameraPosition );


Any insights much appreciated.

Answer

add this to you file declare var com:any; and also read this How can I access Native api in NativeScript when I use Typescript

Comments