Preparing for v2.2.7
MODIFY
README.md
README.md
-# Cordova GoogleMaps plugin for iOS and Android (version 2.2.6)
+# Cordova GoogleMaps plugin for iOS and Android (version 2.2.7)
This plugin is a thin wrapper for [Google Maps Android API](https://developers.google.com/maps/documentation/android/) and [Google Maps SDK for iOS](https://developers.google.com/maps/documentation/ios/).
@@ -85,8 +85,7 @@ $> cordova plugin add cordova-plugin-googlemaps \
- Fix: `map.setOptions()` does not work very after soon from the `MAP_READY` event.
- **v2.2.7**
- - Add: support languages
- (`Arabic`)
+ - Add: support languages (`Arabic` and `Dutch`)
- Fix: Can not build on iOS.
---

MODIFY
package.json
package.json
{
"name": "cordova-plugin-googlemaps",
- "version": "2.2.6",
+ "version": "2.2.7",
"description": "Google Maps native SDK for Android and iOS",
"cordova": {
"id": "cordova-plugin-googlemaps",

MODIFY
plugin.xml
plugin.xml
<?xml version='1.0' encoding='utf-8'?>
-<plugin id="cordova-plugin-googlemaps" version="2.2.7-beta-20180313-1607" 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.2.7" 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="BaseClass" src="www/BaseClass.js">
<runs />

MODIFY
src/android/plugin/google/maps/PluginMap.java
src/android/plugin/google/maps/PluginMap.java
@@ -2297,7 +2297,7 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
String tmp[] = markerTag.split("_");
tmp = markerTag.split("-");
String markerId = tmp[tmp.length - 1];
- String js = String.format(Locale.ENGLISH, "javascript:if(window.cordova){cordova.fireDocumentEvent('%s', {evtName: '%s', callback:'_onMarkerEvent', args:['%s', new plugin.google.maps.LatLng(%f, %f)]});}",
+ String js = String.format(Locale.ENGLISH, "javascript:plugin.google.maps['%s']({evtName: '%s', callback:'_onMarkerEvent', args:['%s', new plugin.google.maps.LatLng(%f, %f)]});",
mapId, eventName, markerId, latLng.latitude, latLng.longitude);
jsCallback(js);
}
@@ -2311,7 +2311,7 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
String tmp[] = markerTag.split("-");
String clusterId = tmp[0];
String markerId = tmp[1];
- String js = String.format(Locale.ENGLISH, "javascript:if(window.cordova){cordova.fireDocumentEvent('%s', {evtName: '%s', callback:'_onClusterEvent', args:['%s', '%s', new plugin.google.maps.LatLng(%f, %f)]});}",
+ String js = String.format(Locale.ENGLISH, "javascript:plugin.google.maps['%s']({evtName: '%s', callback:'_onClusterEvent', args:['%s', '%s', new plugin.google.maps.LatLng(%f, %f)]});",
mapId, eventName, clusterId, markerId, latLng.latitude, latLng.longitude);
jsCallback(js);
}
@@ -2323,13 +2323,13 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
LatLng latLng = activeMarker.getPosition();
Point point = projection.toScreenLocation(latLng);
- String js = String.format(Locale.ENGLISH, "javascript:if(window.cordova){cordova.fireDocumentEvent('%s', {evtName: 'syncPosition', callback:'_onSyncInfoWndPosition', args:[{'x': %d, 'y': %d}]});}",
+ String js = String.format(Locale.ENGLISH, "javascript:plugin.google.maps['%s']({evtName: 'syncPosition', callback:'_onSyncInfoWndPosition', args:[{'x': %d, 'y': %d}]});",
mapId, (int)(point.x / density), (int)(point.y / density));
jsCallback(js);
}
public void onOverlayEvent(String eventName, String overlayId, LatLng point) {
- String js = String.format(Locale.ENGLISH, "javascript:if(window.cordova){cordova.fireDocumentEvent('%s', {evtName: '%s', callback:'_onOverlayEvent', args:['%s', new plugin.google.maps.LatLng(%f, %f)]});}",
+ String js = String.format(Locale.ENGLISH, "javascript:plugin.google.maps['%s']({evtName: '%s', callback:'_onOverlayEvent', args:['%s', new plugin.google.maps.LatLng(%f, %f)]});",
mapId, eventName, overlayId, point.latitude, point.longitude);
jsCallback(js);
}
@@ -2355,7 +2355,7 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
* @param eventName
*/
public void onMapEvent(final String eventName) {
- String js = String.format(Locale.ENGLISH, "javascript:if(window.cordova){cordova.fireDocumentEvent('%s', {evtName: '%s', callback:'_onMapEvent', args:[]});}",
+ String js = String.format(Locale.ENGLISH, "javascript:plugin.google.maps['%s']({evtName: '%s', callback:'_onMapEvent', args:[]});",
mapId, eventName);
jsCallback(js);
}
@@ -2366,7 +2366,7 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
* @param point
*/
public void onMapEvent(final String eventName, final LatLng point) {
- String js = String.format(Locale.ENGLISH, "javascript:if(window.cordova){cordova.fireDocumentEvent('%s', {evtName: '%s', callback:'_onMapEvent', args:[new plugin.google.maps.LatLng(%f, %f)]});}",
+ String js = String.format(Locale.ENGLISH, "javascript:plugin.google.maps['%s']({evtName: '%s', callback:'_onMapEvent', args:[new plugin.google.maps.LatLng(%f, %f)]});",
mapId, eventName, point.latitude, point.longitude);
jsCallback(js);
}
@@ -2521,7 +2521,7 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
@Override
public boolean onMyLocationButtonClick() {
- jsCallback(String.format(Locale.ENGLISH, "javascript:if(window.cordova){cordova.fireDocumentEvent('%s',{evtName: 'my_location_button_click', callback:'_onMapEvent'});}", mapId));
+ jsCallback(String.format(Locale.ENGLISH, "javascript:plugin.google.maps['%s']({evtName: 'my_location_button_click', callback:'_onMapEvent'});", mapId));
return false;
}
@@ -2530,7 +2530,7 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
PluginLocationService.setLastLocation(location);
try {
JSONObject result = PluginUtil.location2Json(location);
- jsCallback(String.format(Locale.ENGLISH, "javascript:if(window.cordova){cordova.fireDocumentEvent('%s',{evtName: 'my_location_click', callback:'_onMapEvent', args: [%s]});}", mapId, result.toString(0)));
+ jsCallback(String.format(Locale.ENGLISH, "javascript:plugin.google.maps['%s']({evtName: 'my_location_click', callback:'_onMapEvent', args: [%s]});", mapId, result.toString(0)));
} catch (JSONException e) {
e.printStackTrace();
}
@@ -2598,7 +2598,7 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
jsCallback(
String.format(
Locale.ENGLISH,
- "javascript:if(window.cordova){cordova.fireDocumentEvent('%s', {evtName:'%s', callback:'_onCameraEvent', args: [%s]});}",
+ "javascript:plugin.google.maps['%s']({evtName:'%s', callback:'_onCameraEvent', args: [%s]});",
mapId, eventName, jsonStr));
}
});
@@ -2663,7 +2663,7 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
jsonStr = result.toString();
}
}
- jsCallback(String.format(Locale.ENGLISH, "javascript:if(window.cordova){cordova.fireDocumentEvent('%s', {evtName:'indoor_building_focused', callback:'_onMapEvent', args: [%s]});}", mapId, jsonStr));
+ jsCallback(String.format(Locale.ENGLISH, "javascript:plugin.google.maps['%s']({evtName:'indoor_building_focused', callback:'_onMapEvent', args: [%s]});", mapId, jsonStr));
}
@Override
@@ -2675,12 +2675,12 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
jsonStr = result.toString();
}
}
- jsCallback(String.format(Locale.ENGLISH, "javascript:if(window.cordova){cordova.fireDocumentEvent('%s', {evtName:'indoor_level_activated', callback:'_onMapEvent', args: [%s]});}", mapId, jsonStr));
+ jsCallback(String.format(Locale.ENGLISH, "javascript:plugin.google.maps['%s']({evtName:'indoor_level_activated', callback:'_onMapEvent', args: [%s]});", mapId, jsonStr));
}
@Override
public void onPoiClick(PointOfInterest pointOfInterest) {
- String js = String.format(Locale.ENGLISH, "javascript:if(window.cordova){cordova.fireDocumentEvent('%s', {evtName: '%s', callback:'_onMapEvent', args:['%s', '%s', new plugin.google.maps.LatLng(%f, %f)]});}",
+ String js = String.format(Locale.ENGLISH, "javascript:plugin.google.maps['%s']({evtName: '%s', callback:'_onMapEvent', args:['%s', '%s', new plugin.google.maps.LatLng(%f, %f)]});",
mapId, "poi_click", pointOfInterest.placeId, pointOfInterest.name, pointOfInterest.latLng.latitude, pointOfInterest.latLng.longitude);
jsCallback(js);
}

MODIFY
src/ios/GoogleMaps/CordovaGoogleMaps.m
src/ios/GoogleMaps/CordovaGoogleMaps.m
- (void)resume:(CDVInvokedUrlCommand *)command {
if (self.pluginLayer != nil) {
self.pluginLayer.isSuspended = false;
- dispatch_semaphore_signal(self.pluginLayer.semaphore);
+ [self.pluginLayer startRedrawTimer];
}
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
- (void)pause:(CDVInvokedUrlCommand *)command {
if (self.pluginLayer != nil) {
self.pluginLayer.isSuspended = true;
+
+ // cancel tht timer
+ [self.pluginLayer stopRedrawTimer];
}
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
self.pluginLayer.isSuspended = false;
- dispatch_semaphore_signal(self.pluginLayer.semaphore);
+ [self.pluginLayer startRedrawTimer];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self.pluginLayer resizeTask:nil];
}];

MODIFY
src/ios/GoogleMaps/GoogleMapsViewController.m
src/ios/GoogleMaps/GoogleMapsViewController.m
- (void)mapView:(GMSMapView *)mapView didTapPOIWithPlaceID:(NSString *)placeID name:(NSString *)name location:(CLLocationCoordinate2D)location {
NSString* jsString = [NSString
- stringWithFormat:@"javascript:cordova.fireDocumentEvent('%@', {evtName: '%@', callback: '_onMapEvent', args: ['%@', '%@', new plugin.google.maps.LatLng(%f,%f)]});",
+ stringWithFormat:@"javascript:plugin.google.maps['%@']({evtName: '%@', callback: '_onMapEvent', args: ['%@', '%@', new plugin.google.maps.LatLng(%f,%f)]});",
self.mapId, @"poi_click", placeID, name, location.latitude, location.longitude];
[self execJS:jsString];
}
- (BOOL)didTapMyLocationButtonForMapView:(GMSMapView *)mapView {
NSString* jsString = [NSString
- stringWithFormat:@"javascript:cordova.fireDocumentEvent('%@', {evtName: '%@', callback: '_onMapEvent', args: []});",
+ stringWithFormat:@"javascript:plugin.google.maps['%@']({evtName: '%@', callback: '_onMapEvent', args: []});",
self.mapId, @"my_location_button_click"];
[self execJS:jsString];
return NO;
NSString* sourceArrayString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSString* jsString = [NSString
- stringWithFormat:@"javascript:cordova.fireDocumentEvent('%@', {evtName: '%@', callback: '_onMapEvent', args: [%@]});",
+ stringWithFormat:@"javascript:plugin.google.maps['%@']({evtName: '%@', callback: '_onMapEvent', args: [%@]});",
self.mapId, @"my_location_click", sourceArrayString];
[self execJS:jsString];
}
CGPoint point = [self.map.projection
pointForCoordinate:CLLocationCoordinate2DMake(position.latitude, position.longitude)];
NSString* jsString = [NSString
- stringWithFormat:@"javascript:cordova.fireDocumentEvent('%@', {evtName: 'syncPosition', callback: '_onSyncInfoWndPosition', args: [{x: %f, y: %f}]});",
+ stringWithFormat:@"javascript:plugin.google.maps['%@']({evtName: 'syncPosition', callback: '_onSyncInfoWndPosition', args: [{x: %f, y: %f}]});",
self.mapId, point.x, point.y ];
[self execJS:jsString];
}
{
NSString* jsString = [NSString
- stringWithFormat:@"javascript:cordova.fireDocumentEvent('%@', {evtName: '%@', callback: '_onMapEvent', args: []});",
+ stringWithFormat:@"javascript:plugin.google.maps['%@']({evtName: '%@', callback: '_onMapEvent', args: []});",
self.mapId, eventName];
[self execJS:jsString];
}
{
NSString* jsString = [NSString
- stringWithFormat:@"javascript:cordova.fireDocumentEvent('%@', {evtName: '%@', callback: '_onMapEvent', args: [new plugin.google.maps.LatLng(%f,%f)]});",
+ stringWithFormat:@"javascript:plugin.google.maps['%@']({evtName: '%@', callback: '_onMapEvent', args: [new plugin.google.maps.LatLng(%f,%f)]});",
self.mapId, eventName, coordinate.latitude, coordinate.longitude];
[self execJS:jsString];
}
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:json options:0 error:nil];
NSString* sourceArrayString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSString* jsString = [NSString
- stringWithFormat:@"javascript:cordova.fireDocumentEvent('%@', {evtName: '%@', callback: '_onCameraEvent', args: [%@]});",
+ stringWithFormat:@"javascript:plugin.google.maps['%@']({evtName: '%@', callback: '_onCameraEvent', args: [%@]});",
self.mapId, eventName, sourceArrayString];
[self execJS:jsString];
// Get the marker plugin
NSString* jsString = [NSString
- stringWithFormat:@"javascript:cordova.fireDocumentEvent('%@', {evtName: '%@', callback: '_onClusterEvent', args: ['%@', '%@', new plugin.google.maps.LatLng(%f, %f)]});",
+ stringWithFormat:@"javascript:plugin.google.maps['%@']({evtName: '%@', callback: '_onClusterEvent', args: ['%@', '%@', new plugin.google.maps.LatLng(%f, %f)]});",
self.mapId, eventName, clusterId, markerId,
marker.position.latitude,
marker.position.longitude];
NSString *markerId = [tmp objectAtIndex:([tmp count] - 1)];
NSString* jsString = [NSString
- stringWithFormat:@"javascript:cordova.fireDocumentEvent('%@', {evtName: '%@', callback: '_onMarkerEvent', args: ['%@', new plugin.google.maps.LatLng(%f, %f)]});",
+ stringWithFormat:@"javascript:plugin.google.maps['%@']({evtName: '%@', callback: '_onMarkerEvent', args: ['%@', new plugin.google.maps.LatLng(%f, %f)]});",
self.mapId, eventName, markerId,
marker.position.latitude,
marker.position.longitude];
- (void)triggerOverlayEvent: (NSString *)eventName overlayId:(NSString*)overlayId coordinate:(CLLocationCoordinate2D)coordinate
{
NSString* jsString = [NSString
- stringWithFormat:@"javascript:cordova.fireDocumentEvent('%@', {evtName: '%@', callback: '_onOverlayEvent', args: ['%@', new plugin.google.maps.LatLng(%f, %f)]});",
+ stringWithFormat:@"javascript:plugin.google.maps['%@']({evtName: '%@', callback: '_onOverlayEvent', args: ['%@', new plugin.google.maps.LatLng(%f, %f)]});",
self.mapId, eventName, overlayId, coordinate.latitude, coordinate.longitude];
[self execJS:jsString];
}
}
//Notify to the JS
NSString* jsString = [NSString
- stringWithFormat:@"javascript:cordova.fireDocumentEvent('%@', {evtName: 'indoor_building_focused', callback: '_onMapEvent'});",
+ stringWithFormat:@"javascript:plugin.google.maps['%@']({evtName: 'indoor_building_focused', callback: '_onMapEvent'});",
self.mapId];
[self execJS:jsString];
}
//Notify to the JS
NSString* jsString = [NSString
- stringWithFormat:@"javascript:cordova.fireDocumentEvent('%@', {evtName: 'indoor_level_activated', callback: '_onMapEvent', args: [%@]});",
+ stringWithFormat:@"javascript:plugin.google.maps['%@']({evtName: 'indoor_level_activated', callback: '_onMapEvent', args: [%@]});",
self.mapId, JSONstring];
[self execJS:jsString];

MODIFY
src/ios/GoogleMaps/MyPluginLayer.h
src/ios/GoogleMaps/MyPluginLayer.h
@property (nonatomic) UIView *webView;
@property (nonatomic) MyPluginScrollView *pluginScrollView;
-@property (nonatomic) NSTimer *redrawTimer;
+@property (atomic) NSTimer *redrawTimer;
@property (nonatomic) BOOL isSuspended;
@property (nonatomic) BOOL stopFlag;
@property (nonatomic) NSOperationQueue *executeQueue;
-@property (nonatomic) dispatch_semaphore_t semaphore;
@property (atomic, strong) NSObject *_lockObject;
- (id)initWithWebView:(UIView *)webView;
- (void)addMapView:(GoogleMapsViewController *)mapCtrl;
- (void)removeMapView:(GoogleMapsViewController *)mapCtrl;
- (void)updateViewPosition:(GoogleMapsViewController *)mapCtrl;
+- (void)startRedrawTimer;
+- (void)stopRedrawTimer;
@end

MODIFY
src/ios/GoogleMaps/MyPluginLayer.m
src/ios/GoogleMaps/MyPluginLayer.m
[self addSubview:self.pluginScrollView];
[self addSubview:self.webView];
-
dispatch_queue_t q_background = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0);
dispatch_async(q_background, ^{
- self.semaphore = dispatch_semaphore_create(0);
+ [self startRedrawTimer];
+ });
+
+ return self;
+}
+
+- (void)startRedrawTimer {
+ if (!self.redrawTimer) {
+
self.redrawTimer = [NSTimer scheduledTimerWithTimeInterval:0.1
target:self
selector:@selector(resizeTask:)
userInfo:nil
repeats:YES];
- });
-
- return self;
}
-
+}
+- (void)stopRedrawTimer {
+ if (self.redrawTimer) {
+ [self.redrawTimer invalidate];
+ self.redrawTimer = nil;
+ }
+}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
CGPoint offset = self.webView.scrollView.contentOffset;
}
- (void)resizeTask:(NSTimer *)timer {
- if (self.isSuspended) {
- @synchronized (self.semaphore) {
- dispatch_semaphore_wait(self.semaphore, DISPATCH_TIME_FOREVER);
- }
- //return;
- }
- if (self.stopFlag) {
+ if (self.isSuspended || self.stopFlag) {
return;
}
self.stopFlag = YES;

MODIFY
www/googlemaps-cdv-plugin.js
www/googlemaps-cdv-plugin.js
@@ -102,25 +102,18 @@ if (!cordova) {
}
document.body.addEventListener("transitionend", function(e) {
- setTimeout(function() {
- common.nextTick(function() {
- if (e.target.hasAttribute("__pluginDomId")) {
- //console.log("transitionend", e.target.getAttribute("__pluginDomId"));
- var isMapChild = false;
- var ele = e.target;
- while(!isMapChild && ele && ele.nodeType === Node.ELEMENT_NODE) {
- isMapChild = ele.hasAttribute("__pluginMapId");
- ele = ele.parentNode;
+ if (!e.target.hasAttribute("__pluginDomId")) {
+ return;
}
- traceDomTree(e.target, e.target.getAttribute("__pluginDomId"), isMapChild);
-
- isSuspended = true;
- isThereAnyChange = true;
- isChecking = false;
+ var cnt = 5;
+ var timer = setInterval(function() {
+ cnt--;
+ if (cnt > 0) {
resetTimer({force: true});
+ } else {
+ clearInterval(timer);
}
- });
- }, 100);
+ }, 50);
}, true);
document.body.addEventListener("scroll", function(e) {
@@ -265,7 +258,7 @@ if (!cordova) {
checkRequested = false;
if (!isThereAnyChange) {
if (!isSuspended) {
- //console.log("-->pause(320)");
+ //console.log("-->pause(269)");
cordova_exec(null, null, 'CordovaGoogleMaps', 'pause', []);
}
@@ -294,7 +287,7 @@ if (!cordova) {
if (touchableMapList.length === 0) {
//console.log("--->touchableMapList.length = 0");
if (!isSuspended) {
-// console.log("-->pause, isSuspended = true");
+ //console.log("-->(298)pause, isSuspended = true");
cordova_exec(null, null, 'CordovaGoogleMaps', 'pause', []);
isSuspended = true;
isThereAnyChange = false;
@@ -390,7 +383,7 @@ if (!cordova) {
// Pass information to native
//-----------------------------------------------------------------
if (isSuspended) {
- //console.log("-->resume(470)");
+ //console.log("-->resume(394)");
cordova_exec(null, null, 'CordovaGoogleMaps', 'resume', []);
isSuspended = false;
}
@@ -407,6 +400,7 @@ if (!cordova) {
isChecking = false;
isThereAnyChange = false;
isSuspended = true;
+ //console.log("---->pause(411)");
cordova_exec(null, null, 'CordovaGoogleMaps', 'pause', []);
}, null, 'CordovaGoogleMaps', 'putHtmlElements', [domPositions]);
child = null;
@@ -589,7 +583,10 @@ if (!cordova) {
var map = new Map(mapId, execCmd);
// Catch all events for this map instance, then pass to the instance.
- document.addEventListener(mapId, nativeCallback.bind(map));
+ //document.addEventListener(mapId, nativeCallback.bind(map));
+ plugin.google.maps[mapId] = nativeCallback.bind(map);
+
+
map.on('div_changed', function(oldDiv, newDiv) {
if (common.isDom(oldDiv)) {
oldDiv.removeAttribute('__pluginMapId');
@@ -654,7 +651,7 @@ if (!cordova) {
});
map.one('remove', function() {
- document.removeEventListener(mapId, nativeCallback);
+ delete plugin.google.maps[mapId];
var div = map.getDiv();
if (!div) {
div = document.querySelector("[__pluginMapId='" + mapId + "']");
@@ -682,6 +679,7 @@ if (!cordova) {
common._clearInternalCache();
isSuspended = true;
+ //console.log("---->pause(688)");
cordova_exec(null, null, 'CordovaGoogleMaps', 'pause', []);
}
});
@@ -731,6 +729,7 @@ if (!cordova) {
cordova_exec(function() {
map.getMap.apply(map, args);
}, null, 'CordovaGoogleMaps', 'putHtmlElements', [domPositions]);
+ //console.log("-->resume(737)");
}, null, 'CordovaGoogleMaps', 'resume', []);
//resetTimer({force: true});
} else {

Preparing for v2.2.7