Angular 错误类型错误:无法读取属性';getProjection';未定义的
我这样做是因为我有一个简单的问题。只有我需要在Typescript代码中使用它 在以下代码中:Angular 错误类型错误:无法读取属性';getProjection';未定义的,angular,location,maps,nativescript,Angular,Location,Maps,Nativescript,我这样做是因为我有一个简单的问题。只有我需要在Typescript代码中使用它 在以下代码中: googleMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() { @Override public void onCameraChange(CameraPosition position) { LatLngBounds bound
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)
}
在her中,显示以下错误:
请你能和我分享一下如何解决这个问题吗?我想得到API要求的纬度、长度和半径,我可以从中心点得到纬度和液化天然气,但找不到获得半径的方法
更新:
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)
}
展示:
应用程序自动关闭
您可能需要导入gMap并将实例添加到构造函数中您可能需要导入gMap并将实例添加到构造函数中您看过这个吗?尝试注释该行,找出它的确切关闭位置。可能Android Studio中的logcat会给出详细的日志,看看你是否在那里找到了相关的东西。你看过这个吗?试着评论一下这行,找出它的确切位置。可能是Android Studio中的logcat会给出详细的日志,看看你是否在那里找到了相关的内容。但是你仍然无法读取Undelinedi的属性“getProjection”,你可以获取
JS:bounds LatLngBounds{southwest=lat/lng:(-66.418115185001424,-63.11405181884765),Northwest=lat/lng:(66.41891785546429,63.11484139412641)}
但问题是不同的,直到你无法读取Undelinedi的属性“getProjection”,你才能得到JS:bounds LatLngBounds{southwest=lat/lng:(-66.41815185001424,-63.11405181884765),Northwest=lat/lng:(66.41891785546429,63.11484139412641)}
但问题是不同的
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)