hansemannn / titanium-googlemaps

🗺 Use the Google Maps SDK in Titanium
Other
87 stars 26 forks source link

Support Map Clustering and CameraUpdate API #58

Closed hansemannn closed 7 years ago

hansemannn commented 7 years ago
mention-bot commented 7 years ago

@hansemannn, thanks for your PR! By analyzing the history of the files in this pull request, we identified @yozef to be a potential reviewer.

hansemannn commented 7 years ago

@yozef haha, check the new mention-bot :-D You don't need to review so far.

yozef commented 7 years ago

Just tested out the MapStyling - looking nice :) The Marker is always showing at the right long/lat... haven't had any issues so far! haven't tested the other features of 2.6 Beta 3

hansemannn commented 7 years ago

Yeah, this one will go into 2.7.0 already. Luckily had some time today evening.

hansemannn commented 7 years ago

@yozef I'm done! Can you give it a quick review / FT? I added the example/clustering.js for an easy example. The icon used is attached here, name it marker@2x.png and place it in the project root.

marker 2x

yozef commented 7 years ago

Sure, will test in on iPhone 6 & 7 devices.

yozef commented 7 years ago

I noticed a bug with the Annotation pointing to long/lat: 0,0 instead of the ones provided, If there is the image param in the creation of the annotation, similarly, same behaviour if rotation or groundOffset (maybe others) are added to the creation of the annotation, the location on the map when added will be at 0,0 instead of the long/lat passed.

dave101 commented 7 years ago

Just a suggestion; it may be a good idea to allow for the fitBounds method to allow for an infinite amount of coordinates, rather than just the 2.

I have made a change to my local version; that loops through an array of coords, which seems to work well:

`- (void)fitBounds:(id)args { ENSURE_UI_THREAD(fitBounds, args); ENSURE_SINGLE_ARG(args, NSDictionary);

id _padding = [args objectForKey:@"padding"];
id _insets = [args objectForKey:@"insets"];
id _bounds = [args objectForKey:@"bounds"];

CLLocationCoordinate2D coordinate1 = CLLocationCoordinate2DMake([TiUtils doubleValue:[_bounds[0] valueForKey:@"latitude"]], [TiUtils doubleValue:[_bounds[0] valueForKey:@"longitude"]]);

GMSCoordinateBounds *coordinateBounds = [[GMSCoordinateBounds alloc] initWithCoordinate:coordinate1
                                                                             coordinate:coordinate1];

for (id point in _bounds){
    if ([point isKindOfClass:[NSDictionary class]]) {
        CLLocationCoordinate2D _coord = CLLocationCoordinate2DMake([TiUtils doubleValue:[point valueForKey:@"latitude"]], [TiUtils doubleValue:[point valueForKey:@"longitude"]]);

        coordinateBounds = [coordinateBounds includingCoordinate:_coord];
    }
}

if (_padding && _insets) {
    NSLog(@"[ERROR] Cannot use both `padding` and `insets` in the `fitBounds` method. Check the Google Maps docs for more infos: https://developers.google.com/maps/documentation/ios-sdk/reference/interface_g_m_s_camera_update.html#abd6fdfa8800f8b2d9ba00af5e44fa385");
    return;
}

if (_padding) {
    cameraUpdate = [GMSCameraUpdate fitBounds:coordinateBounds
                                  withPadding:[TiUtils floatValue:_padding]];
    return;
}

if (_insets) {
    cameraUpdate = [GMSCameraUpdate fitBounds:coordinateBounds
                               withEdgeInsets:[TiUtils contentInsets:_insets]];
    return;
}

cameraUpdate = [GMSCameraUpdate fitBounds:coordinateBounds];

}`

Therefore in titanium:

cameraUpdate.fitBounds({ // IMPORTANT: Use eitherpaddingorinsets, not both together padding: 70, //insets: {top: 10, left: 10, bottom: 10, right: 10}, bounds: [ { latitude : parseFloat(-37.74708), longitude : parseFloat(145.211891), }, { latitude : parseFloat(-37.815708), longitude : parseFloat(145.221891), }, { latitude : parseFloat(-37.875708), longitude : parseFloat(145.281891), } ] });