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

时间:2019-09-27 09:19:19

标签: angular location maps nativescript

我遵循此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,但是找不到获取半径的方法。

更新:

  public  onCameraChange(arg) {
     this.gMap = event.object.gMap;
                    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: bounds LatLngBounds{southwest=lat/lng: (-66.41815185001424,-63.11405181884765), northeast=lat/lng: (66.41891785546429,63.11484139412641)}
JS: northeast lat/lng: (66.41891785546429,63.11484139412641)
JS: southwest lat/lng: (-66.41815185001424,-63.11405181884765)

应用程序自动关闭

  1. 该部分的半径如何计算?
  2. 为什么我的申请关闭了?

1 个答案:

答案 0 :(得分:0)

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