Fix: Street View: App crashes if no panorama available for the target set
MODIFY
README.md
README.md
- Update: (iOS) Remove "NSData+Base64" library. No longer necessary.
- Update: (js) ionic 4 hides Google Maps view.
- Fix: (Browser) `MarkerCluster.remove()` does not work on browser platform.
+ - Fix: (Android/iOS/Browser) App crashes (or error) if no panorama available.
- **v2.4.6**
- Fix: (iOS) Only `src/ios/check_sdk_version.js` error.

MODIFY
plugin.xml
plugin.xml
<?xml version='1.0' encoding='utf-8'?>
-<plugin id="cordova-plugin-googlemaps" version="2.5.0-beta-20181219-2113" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
+<plugin id="cordova-plugin-googlemaps" version="2.5.0-beta-20181219-2143" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<name>cordova-plugin-googlemaps</name>
<js-module name="Promise" src="www/Promise.js" />
<asset src="www/promise-7.0.4.min.js.map" target="promise-7.0.4.min.js.map" />

MODIFY
src/android/plugin/google/maps/PluginStreetViewPanorama.java
src/android/plugin/google/maps/PluginStreetViewPanorama.java
@@ -393,8 +393,9 @@ public class PluginStreetViewPanorama extends MyPlugin implements
@Override
public void onStreetViewPanoramaChange(StreetViewPanoramaLocation streetViewPanoramaLocation) {
-
try {
+ String jsonStr = "null";
+ if (streetViewPanoramaLocation != null) {
JSONObject location = new JSONObject();
location.put("panoId", streetViewPanoramaLocation.panoId);
@@ -412,7 +413,8 @@ public class PluginStreetViewPanorama extends MyPlugin implements
}
location.put("links", links);
- String jsonStr = location.toString(0);
+ jsonStr = location.toString(0);
+ }
jsCallback(
String.format(
Locale.ENGLISH,

MODIFY
src/browser/PluginStreetViewPanorama.js
src/browser/PluginStreetViewPanorama.js
-
var utils = require('cordova/utils'),
event = require('cordova-plugin-googlemaps.event'),
BaseClass = require('cordova-plugin-googlemaps.BaseClass');
@@ -74,12 +73,12 @@ function PluginStreetViewPanorama(panoramaId, options) {
if (status === google.maps.StreetViewStatus.OK) {
resolve(data.location.pano);
} else {
- reject();
+ resolve(null);
}
});
} else {
- resolve();
+ resolve(null);
}
})
.then(function(panoId) {
@@ -136,6 +135,9 @@ function PluginStreetViewPanorama(panoramaId, options) {
panorama.addListener('pov_changed', self._onCameraEvent.bind(self, panorama));
panorama.addListener('zoom_changed', self._onCameraEvent.bind(self, panorama));
+ if (!panoId) {
+ self._onPanoChangedEvent(null);
+ }
});
@@ -243,12 +245,15 @@ PluginStreetViewPanorama.prototype.setPosition = function(onSuccess, onError, ar
if (status === google.maps.StreetViewStatus.OK) {
resolve(data.location.pano);
} else {
- reject();
+ resolve(null);
}
});
})
.then(function(panoId) {
panorama.setPano(panoId);
+ if (!panoId) {
+ self._onPanoChangedEvent(null);
+ }
onSuccess();
})
.catch(onError);
@@ -306,9 +311,12 @@ PluginStreetViewPanorama.prototype._onCameraEvent = function(panorama) {
};
PluginStreetViewPanorama.prototype._onPanoChangedEvent = function(panorama) {
var self = this;
+ var locationInfo = null;
+
+ if (panorama) {
var location = panorama.getLocation();
- var locationInfo = {
+ locationInfo = {
'panoId': location.pano,
'latLng': {
'lat': location.latLng.lat(),
@@ -325,6 +333,7 @@ PluginStreetViewPanorama.prototype._onPanoChangedEvent = function(panorama) {
};
});
}
+ }
if (self.__pgmId in plugin.google.maps) {
plugin.google.maps[self.__pgmId]({
'evtName': event.PANORAMA_LOCATION_CHANGE,

MODIFY
src/ios/GoogleMaps/PluginStreetViewPanoramaController.m
src/ios/GoogleMaps/PluginStreetViewPanoramaController.m
- (void) locationChangeEvent:(CLLocationCoordinate2D)coordinate {
+ NSString* sourceArrayString = @"null";
+ if (self.panoramaView.panorama) {
NSMutableDictionary *location = [NSMutableDictionary dictionary];
[location setObject:self.panoramaView.panorama.panoramaID forKey:@"panoId"];
[location setObject:links forKey:@"links"];
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:location options:0 error:nil];
- NSString* sourceArrayString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
+ sourceArrayString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
+ }
NSString* jsString = [NSString
stringWithFormat:@"javascript:if('%@' in plugin.google.maps){plugin.google.maps['%@']({evtName: '%@', callback: '_onPanoramaLocationChange', args: [%@]});}",
self.overlayId, self.overlayId, @"panorama_location_change", sourceArrayString];

MODIFY
www/StreetViewPanorama.js
www/StreetViewPanorama.js
@@ -301,12 +301,13 @@ StreetViewPanorama.prototype._onPanoramaCameraChange = function(eventName, camer
StreetViewPanorama.prototype._onPanoramaLocationChange = function(eventName, panoramaLocation) {
var self = this;
self.set('location', panoramaLocation);
- self.set('pano', panoramaLocation.panoId);
- self.set('position', panoramaLocation.latLng);
+ self.set('pano', panoramaLocation ? panoramaLocation.panoId : null);
+ self.set('position', panoramaLocation ? panoramaLocation.latLng : null);
if (self._isReady) {
self._onPanoramaEvent(eventName, panoramaLocation);
}
};
+
StreetViewPanorama.prototype._onPanoramaEvent = function() {
var self = this;
if (self._isReady) {

Fix: Street View: App crashes if no panorama available for the target set #2518