Skip to content

Commit

Permalink
Fix annotations properties after mutating, update Google Maps to 2.1.…
Browse files Browse the repository at this point in the history
…0, expose Map Styles (#51)

* Prepare new 2.5.1 version

* Attempt fix to update markers on position-changes

* Fix possible memory-leaks, remove synthesize

* Add back synthesize for markers to ease setters

* Add back .travis to validate CI-test builds

* Trigger .travis CI-build

* Use locks to ensure thread-safety for annotations

* Revert "Use locks to ensure thread-safety for annotations"

This reverts commit 3b8c558.

* Use 5.5.1.GA, remove locks, remove build.py

* Fix annotations, update copyright

* Update GoogleMaps iOS-SDK to 2.1.0

* Expose mapStyle property, bump to 2.6.0

* Update bundle files from Google Maps SDK 2.1.0

* Use UUID to identify markers

* Use GCD to precent race-conds, fix autocomplete

* Update example with autocomplete-configuration

* Add address components to autocomplete result

* Improve GCD

* Update example file, fix GCD for kroll-thread

* Fix latitude for legacy namespace
  • Loading branch information
hansemannn authored Dec 27, 2016
1 parent 963fb6d commit 5f53010
Show file tree
Hide file tree
Showing 214 changed files with 495 additions and 443 deletions.
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ Ti.GoogleMaps is an open-source project to support the Google Maps iOS-SDK in Ap
- [x] Polygon overlay
- [x] Polyline overlay
- [x] Circle overlay
- [x] Autocompletion dialog
- [x] All delegates (exposed as events)

Requirements
---------------
- Titanium Mobile SDK 5.0.2.GA or later
- Titanium Mobile SDK 5.2.2.GA or later
- iOS 7.1 or later
- Xcode 6.4 or later

Expand All @@ -38,15 +39,13 @@ Edit the modules section of your `tiapp.xml` file to include this module:
Initialize the module by setting the Google Maps API key you can get from [here](https://developers.google.com/maps/signup).
```javascript
var maps = require("ti.googlemaps");
maps.setAPIKey("<YOUR_API_KEY>");
maps.setAPIKey("<YOUR_GOOGLE_MAPS_API_KEY>");
```

### Build
If you want to build the module from the source, you need to check some things beforehand:
- The latest GoogleMaps.framework is > 100 MB, so Github won't allow pushing it to the repository. So you need to get the [latest Google Maps iOS](https://developers.google.com/maps/documentation/ios-sdk/) and copy it into `/ios/platform/GoogleMaps.framework`.
- Make sure to link the framework in "Build Phases" -> "Link Binary With Libraries" -> Select "GoogleMaps.framework"
- Set the `TITANIUM_SDK_VERSION` inside the `ios/titanium.xcconfig` file to the Ti.SDK version you want to build with.
- Build the project using the `ios/build.py` with `python [path/to/module]/ios/build.py` for Ti.SDK < 5.2.0 and `appc ti build -p ios --build-only` for Ti.SDK >= 5.2.1
- Build the project with `ti build -p ios --build-only` for Ti.SDK >= 5.2.2
- Check the [releases tab](https://github.com/hansemannn/ti.googlemaps/releases) for stable pre-packaged versions of the module

Features
Expand Down Expand Up @@ -112,9 +111,15 @@ mapView.allowScrollGesturesDuringRotateOrZoom = false;

Map Insets:
```javascript
$.mapview.mapInsets = { bottom:200 };
mapView.mapInsets = { bottom:200 };
```

Map Style:
```javascript
mapView.mapStyle = "JSON_STYLE_GOES_HERE";
```
See [this link](https://developers.google.com/maps/documentation/ios-sdk/hiding-features) for more infos on map styling.

Animate to a location:
```javascript
mapView.animateToLocation({
Expand Down Expand Up @@ -213,6 +218,9 @@ var dialog = GoogleMaps.createAutocompleteDialog({
tintColor: "blue"
});

// You need a Google Places API key from the Google Developer Console
dialog.configure("<YOUR_GOOGLE_PLACES_API_KEY>");

dialog.open();
```

Expand Down
11 changes: 9 additions & 2 deletions example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ var win = Ti.UI.createWindow({
includeOpaqueBars: true,
extendEdges: [Ti.UI.EXTEND_EDGE_ALL]
});
var nav = Ti.UI.iOS.createNavigationWindow({window: win});

var maps = require("ti.googlemaps");
maps.setAPIKey("<YOUR_GOOGLE_MAPS_API_KEY>");
Expand Down Expand Up @@ -41,7 +40,7 @@ var companies = {
/*
* MapView
*/
var mapView = maps.createMapView({
var mapView = maps.createView({
mapType: maps.MAP_TYPE_TERRAIN,
indoorEnabled: true,
indoorPicker: false,
Expand Down Expand Up @@ -229,6 +228,9 @@ function openAutocompleteDialog() {
primaryTextHighlightColor: "blue",
tintColor: "blue"*/
});


dialog.configure("<YOUR_GOOGLE_PLACES_API_KEY>");

dialog.addEventListener("success", function(e) {
Ti.API.info(e.place);
Expand Down Expand Up @@ -267,4 +269,9 @@ searchButton.addEventListener("click", openAutocompleteDialog);

win.setRightNavButton(searchButton);
win.add(mapView);

var nav = Ti.UI.iOS.createNavigationWindow({
window: win
});

nav.open();
8 changes: 8 additions & 0 deletions ios/Classes/TiGooglemapsAnnotationProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,12 @@
*/
-(void)setUserData:(id)value;

/**
* Updates the annotation location (latitude, longitude)
*
* @param value The locations data
* @since 2.4.0
*/
-(void)updateLocation:(id)args;

@end
14 changes: 11 additions & 3 deletions ios/Classes/TiGooglemapsAnnotationProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

@implementation TiGooglemapsAnnotationProxy


@synthesize marker = _marker;

-(GMSMarker*)marker
Expand All @@ -19,6 +18,7 @@ -(GMSMarker*)marker
_marker = [GMSMarker new];

[_marker setPosition:CLLocationCoordinate2DMake([TiUtils doubleValue:[self valueForKey:@"latitude"]],[TiUtils doubleValue:[self valueForKey:@"longitude"]])];
[_marker setUserData:@{@"uuid": [[NSUUID UUID] UUIDString]}];
}

return _marker;
Expand All @@ -36,6 +36,7 @@ -(void)setMarker:(GMSMarker*)marker

-(void)dealloc
{
RELEASE_TO_NIL(_marker)
[super dealloc];
}

Expand Down Expand Up @@ -143,8 +144,15 @@ -(void)setRotation:(id)value
-(void)setUserData:(id)value
{
ENSURE_UI_THREAD_1_ARG(value);
[[self marker] setUserData:value];
[self replaceValue:value forKey:@"userData" notification:NO];
NSMutableDictionary *result = value;

// Hook in internal uuid
if ([[self marker] userData] != value) {
[result setObject:[[[self marker] userData] valueForKey:@"uuid"] forKey:@"uuid"];
}

[[self marker] setUserData:result];
[self replaceValue:result forKey:@"userData" notification:NO];
}

-(void)updateLocation:(id)args
Expand Down
37 changes: 33 additions & 4 deletions ios/Classes/TiGooglemapsAutocompleteDialogProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ - (GMSAutocompleteViewController*)dialog
return dialog;
}

- (void)configure:(id)value
{
ENSURE_SINGLE_ARG(value, NSString);
[GMSPlacesClient provideAPIKey:value];
}

- (void)open:(id)args
{
[self rememberSelf];
Expand Down Expand Up @@ -85,7 +91,7 @@ - (void)viewController:(GMSAutocompleteViewController *)viewController didAutoco
{
if ([self _hasListeners:@"success"]) {
[self fireEvent:@"success" withObject:@{
@"place": [self dictionaryFromPlace:place]
@"place": [TiGooglemapsAutocompleteDialogProxy dictionaryFromPlace:place]
}];
}

Expand Down Expand Up @@ -117,24 +123,47 @@ - (void)wasCancelled:(GMSAutocompleteViewController *)viewController

- (void)closeDialog
{
[[self dialog] setDelegate:nil];
[[self dialog] dismissViewControllerAnimated:YES completion:nil];
[self forgetSelf];
RELEASE_TO_NIL(dialog);
}

- (NSDictionary*)dictionaryFromPlace:(GMSPlace*)place
+ (NSDictionary*)dictionaryFromPlace:(GMSPlace*)place
{
return @{
@"name": [place name],
@"placeID": [place placeID],
@"latitude": NUMDOUBLE([place coordinate].latitude),
@"longitude": NUMDOUBLE([place coordinate].longitude),
@"formattedAddress": [place formattedAddress]
@"formattedAddress": [place formattedAddress],
@"addressComponents": [TiGooglemapsAutocompleteDialogProxy arrayFromAddressComponents:[place addressComponents]]
};
}

- (NSDictionary*)dictionaryFromPrediction:(GMSAutocompletePrediction*)prediction
+ (id)arrayFromAddressComponents:(NSArray<GMSAddressComponent*>*)addressComponents
{
if (addressComponents == nil) {
return [NSNull null];
}

NSMutableArray *result = [NSMutableArray new];
for (GMSAddressComponent *addressComponent in addressComponents) {
[result addObject:@{
@"type": addressComponent.type,
@"name":addressComponent.name
}];
}

return result;
}

+ (id)dictionaryFromPrediction:(GMSAutocompletePrediction*)prediction
{
if (prediction == nil) {
return nil;
}

return @{
@"attributedFullText": [[prediction attributedFullText] string],
@"attributedPrimaryText": [[prediction attributedPrimaryText] string],
Expand Down
2 changes: 1 addition & 1 deletion ios/Classes/TiGooglemapsCircleProxy.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2015 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2009-Present by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
Expand Down
10 changes: 7 additions & 3 deletions ios/Classes/TiGooglemapsCircleProxy.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2015 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2009-Present by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
Expand All @@ -9,8 +9,6 @@

@implementation TiGooglemapsCircleProxy

@synthesize circle = _circle;

-(GMSCircle*)circle
{
if (_circle == nil) {
Expand All @@ -21,6 +19,12 @@ -(GMSCircle*)circle
return _circle;
}

-(void)dealloc
{
RELEASE_TO_NIL(_circle);
[super dealloc];
}

#pragma mark Public APIs

-(void)setCenter:(id)args
Expand Down
4 changes: 2 additions & 2 deletions ios/Classes/TiGooglemapsConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ typedef NS_ENUM(NSUInteger, TiGooglemapsOverlayType) {
TiGooglemapsOverlayTypeUnknown = 0,
TiGooglemapsOverlayTypePolygon,
TiGooglemapsOverlayTypePolyline,
TiGooglemapsOverlayTypeCircle,
};
TiGooglemapsOverlayTypeCircle
};
2 changes: 1 addition & 1 deletion ios/Classes/TiGooglemapsMapView.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2015 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2009-Present by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
Expand Down
29 changes: 17 additions & 12 deletions ios/Classes/TiGooglemapsMapView.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2015 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2009-Present by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
Expand All @@ -15,8 +15,6 @@

@implementation TiGooglemapsMapView

@synthesize mapView = _mapView;

#define DEPRECATED(from, to, in) \
NSLog(@"[WARN] Ti.GoogleMaps: %@ is deprecated since %@ in favor of %@", from, to, in);\

Expand All @@ -37,6 +35,12 @@ -(GMSMapView*)mapView
return _mapView;
}

-(void)dealloc
{
RELEASE_TO_NIL(_mapView);
[super dealloc];
}

-(TiGooglemapsMapViewProxy*)mapViewProxy
{
return (TiGooglemapsMapViewProxy*)[self proxy];
Expand Down Expand Up @@ -75,7 +79,7 @@ - (void)mapView:(GMSMapView *)mapView didChangeCameraPosition:(GMSCameraPosition
if ([[self proxy] _hasListeners:@"regionchanged"]) {
[[self proxy] fireEvent:@"regionchanged" withObject:@{
@"map" : [self proxy],
@"latitude" : NUMDOUBLE(position.target.longitude),
@"latitude" : NUMDOUBLE(position.target.latitude),
@"longitude" : NUMDOUBLE(position.target.longitude),
}];
}
Expand Down Expand Up @@ -164,7 +168,7 @@ - (void)mapView:(GMSMapView *)mapView didTapOverlay:(GMSOverlay *)overlay
}
if ([[self proxy] _hasListeners:@"click"]) {
[[self proxy] fireEvent:@"click" withObject:@{
@"clicksource": NUMINT([self overlayTypeFromOverlay:overlay]),
@"clicksource": [self overlayTypeFromOverlay:overlay],
@"map": [self proxy],
@"overlay": [self overlayProxyFromOverlay:overlay]
}];
Expand Down Expand Up @@ -239,20 +243,21 @@ -(NSDictionary*)dictionaryFromCoordinate:(CLLocationCoordinate2D)coordinate
};
}

-(TiGooglemapsOverlayType)overlayTypeFromOverlay:(GMSOverlay*)overlay
-(id)overlayTypeFromOverlay:(GMSOverlay*)overlay
{
ENSURE_UI_THREAD(overlayTypeFromOverlay, overlay);

if([overlay isKindOfClass:[GMSPolygon class]]) {
return TiGooglemapsOverlayTypePolygon;
return NUMINTEGER(TiGooglemapsOverlayTypePolygon);
} else if([overlay isKindOfClass:[GMSPolyline class]]) {
return TiGooglemapsOverlayTypePolyline;
return NUMINTEGER(TiGooglemapsOverlayTypePolyline);
} else if([overlay isKindOfClass:[GMSCircle class]]) {
return TiGooglemapsOverlayTypeCircle;
return NUMINTEGER(TiGooglemapsOverlayTypeCircle);
}

NSLog(@"[WARN] Unknown overlay provided: %@", [overlay class])
return [NSNull null];
NSLog(@"[ERROR] Unknown overlay provided: %@", [overlay class])

return NUMINTEGER(TiGooglemapsOverlayTypeUnknown);
}

-(id)annotationProxyFromMarker:(GMSMarker*)marker
Expand Down
5 changes: 4 additions & 1 deletion ios/Classes/TiGooglemapsMapViewProxy.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2015 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2009-Present by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
Expand All @@ -12,6 +12,9 @@
TiGooglemapsMapViewProxy* mapView;
NSMutableArray *markers;
NSMutableArray *overlays;

@private
dispatch_queue_t q;
}


Expand Down
Loading

0 comments on commit 5f53010

Please sign in to comment.