ionic-team / ionic-team/ionic-native-google-maps
VisibleRegion.toUrlValue() return error
- Ngôn ngữ chính
- TypeScript
- Star
- 215
- Fork
- 119
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
**I'm submitting a ...** (check one with "x")
- [ ] question
- [X] any problem or bug report
- [ ] feature request
**If you choose 'problem or bug report', please select OS:** (check one with "x")
- [ ] **Android**
- [ ] **iOS**
- [X] **Browser**
**cordova information:** (run `$> cordova plugin list`)
```
cordova-plugin-device 2.0.2 "Device"
cordova-plugin-googlemaps 2.7.1 "cordova-plugin-googlemaps"
cordova-plugin-ionic-keyboard 2.2.0 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 5.0.0 "cordova-plugin-ionic-webview"
cordova-plugin-splashscreen 6.0.2 "Splashscreen"
cordova-plugin-statusbar 2.4.2 "StatusBar"
```
**If you use `@ionic-native/google-maps`, please tell the package.json (only `@ionic-native/core` and `@ionic-native/google-maps` are fine mostly)**
```
"@ionic-native/core": "^5.36.0",
"@ionic-native/google-maps": "^5.5.0",
```
**Current behavior:**
This code:
```typescript
const map = GoogleMaps.create('map-canvas', {
mapType: GoogleMapsMapTypeId.ROADMAP,
camera: {
target: {
lat: -15.800739,
lng: -47.861314
},
zoom: 15
}
});
map.on(GoogleMapsEvent.MAP_READY).subscribe(()=>{
console.log(map.getVisibleRegion().toUrlValue());
});
```
produces this error:
```
ERROR TypeError: this.southwest.toUrlValue is not a function
at LatLngBounds.toUrlValue (LatLngBounds.js:36:31)
at SafeSubscriber._next (map.service.ts:131:42)
```
**Expected behavior:**
Expected to get "[lat_sw,lng_sw,lat_ne,lng_ne]" on the terminal
Inspecting where the code fails:
```typescript
LatLngBounds.prototype.toUrlValue = function (precision) {
precision = precision || 6;
return '[' + this.southwest.toUrlValue(precision) + ',' + this.northeast.toUrlValue(precision) + ']';
};
```
It seems that the function expects that this.southwest and this.northeast are of type LatLng which implements toUrlValue().
Howerver, VisibleRegion class defines both as ILatLng which does not implement toUrlValue().
Workaround: convert VisibleRegion.southwest and VisibleRegion.northeast to LatLng
```typescript
const map = GoogleMaps.create('map-canvas', {
mapType: GoogleMapsMapTypeId.ROADMAP,
camera: {
target: {
lat: -15.800739,
lng: -47.861314
},
zoom: 15
}
});
map.on(GoogleMapsEvent.MAP_READY).subscribe(()=>{
const visibleRegion = map.getVisibleRegion();
//CONVERT SOUTHWEST AND NORTHEAST TO LATLNG
const southwest = visibleRegion.southwest;
const northeast = visibleRegion.northeast;
visibleRegion.southwest = new LatLng(southwest.lat,southwest.lng);
visibleRegion.northeast = new LatLng(northeast.lat,northeast.lng);
console.log(visibleRegion.toUrlValue());
});
```
Result:
```
[-15.812301,-47.869897,-15.789176,-47.852731]
```
Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu từ LatLngBounds.toUrlValue() và kiểm tra các định nghĩa của VisibleRegion, ILatLng và LatLng để xác nhận sự không khớp kiểu được mô tả trong báo cáo. Tái hiện ví dụ trên trình duyệt và xác minh rằng việc gọi trực tiếp toUrlValue() trên vùng hiển thị sẽ trả về chuỗi tọa độ tây nam và đông bắc như mong đợi mà không cần workaround.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- typescript
- Lĩnh vực
- frontend, mobile-dev
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 42/100