ERROR TypeError:无法读取未定义的属性'getProjection'

问题描述 投票:0回答:1

我遵循此post,因为我有一个简单的问题。只有我需要在Typescript代码中使用它。

在Android中,此代码:

   googleMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
            @Override
            public void onCameraChange(CameraPosition position) {
                LatLngBounds bounds = googleMap.getProjection().getVisibleRegion().latLngBounds;
                LatLng northeast = bounds.northeast;
                LatLng southwest = bounds.southwest;

                Context context = getApplicationContext();
                CharSequence text = "ne:"+northeast+" sw:"+southwest;
                int duration = Toast.LENGTH_SHORT;

                Toast toast = Toast.makeText(context, text, duration);
                toast.show();
            }
        });

我需要用Typescript / Nativescript代码编写,并这样写:

  public  onCameraChange() {
            var bounds = this.gMap.getProjection().getVisibleRegion().latLngBounds;
            console.log('bounds', bounds)
            var northeast = bounds.northeast;
            console.log('northeast', northeast)
            var southwest = bounds.southwest;
            console.log('southwest', southwest)

            var context = application.android.context.getApplicationContext();
            var text = "ne:"+northeast+" sw:"+southwest;
            console.log('context,text', context,text)
        }

在她面前,显示此错误:

JS: ERROR TypeError: Cannot read property 'getProjection' of undefined
JS: ERROR CONTEXT {
JS:   "view": {
JS:     "def": {
JS:       "nodeFlags": 16793601,
JS:       "rootNodeFlags": 1,
JS:       "nodeMatchedQueries": 0,
JS:       "flags": 0,
JS:       "nodes": [
JS:         {
JS:           "nodeIndex": 0,
JS:           "parent": null,
JS:           "renderParent": null,
JS:           "bindingIndex": 0,
JS:           "outputIndex": 0,
JS:           "checkIndex": 0,
JS:           "flags": 1,
JS:           "childFlags": 16793601,
JS:           "directChildFlags": 16777217,
JS:           "childMatchedQueries": 0,
JS:           "matchedQueries": {},
JS:           "matchedQueryIds": 0,
JS:           "references": {},
JS:           "ngContentIndex": null,
JS:           "childCount": 9,
JS:           "bindings": [],
JS:           "bindingFlags": 0,
JS:           "outputs": [],
JS:           "element": {
JS:             "ns": "",
JS:             "name": "GridLayout",
JS:             "attrs": [
JS:               [
JS:                 "",
JS:                 "class",
JS:                 "page"
JS:               ]
JS:             ],
JS:             "template": null,
JS:             "componentProvider": null,
JS:             "componentView": null...

请您与我分享如何解决的任何想法?我想获取需要lat,long和radius的API,我可以从中心点获取lat和lng,但是找不到获取radius的方法。

angular location maps nativescript
1个回答
0
投票

您可能需要导入gMap并将实例添加到构造函数中

© www.soinside.com 2019 - 2024. All rights reserved.