Skip to content

Commit

Permalink
06-17-2018
Browse files Browse the repository at this point in the history
* Added iOS version of extra data for Location updates.
* Added extra MapOptions attributes.
- showMyLocationButton = show/hide button to center map on user location.
- showCompassButton = show/hide button to change orientation of map.
- hideToolbar = show/hide toolbar on Map Activity/View.
* Added iOS controls for MapOptions Attributes listed above.
* FIX: Fixed iOS bug that avoided the location updates and button to show properly.
  • Loading branch information
LJaraCastillo committed Jun 18, 2018
1 parent 7884932 commit d3407b4
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*___Generated_by_IDEA___*/

package com.apptreesoftware.mapviewexample;

/* This stub is only used by the IDE. It is NOT the Manifest class actually packed into the APK */
public final class Manifest {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*___Generated_by_IDEA___*/

package com.apptreesoftware.mapviewexample;

/* This stub is only used by the IDE. It is NOT the R class actually packed into the APK */
public final class R {
}
2 changes: 2 additions & 0 deletions example/ios/Flutter/flutter_assets/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ source_map_stack_trace
stream_channel
typed_data
utf
vm_service_client

Copyright 2015, the Dart project authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -3121,6 +3122,7 @@ glob
http
http_multi_server
http_parser
json_rpc_2
matcher
path
pool
Expand Down
Binary file modified example/ios/Flutter/flutter_assets/isolate_snapshot_data
Binary file not shown.
Binary file modified example/ios/Flutter/flutter_assets/kernel_blob.bin
Binary file not shown.
Binary file modified example/ios/Flutter/flutter_assets/platform.dill
Binary file not shown.
Binary file modified example/ios/Flutter/flutter_assets/vm_snapshot_data
Binary file not shown.
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ PODS:

DEPENDENCIES:
- Flutter (from `/Users/ceisufro/flutter/bin/cache/artifacts/engine/ios`)
- map_view (from `/Users/ceisufro/AndroidStudioProjects/flutter_map_view/ios`)
- map_view (from `/Users/ceisufro/AndroidStudioProjects/flutter_google_map_view/ios`)

SPEC REPOS:
https://github.com/cocoapods/specs.git:
Expand All @@ -21,7 +21,7 @@ EXTERNAL SOURCES:
Flutter:
:path: "/Users/ceisufro/flutter/bin/cache/artifacts/engine/ios"
map_view:
:path: "/Users/ceisufro/AndroidStudioProjects/flutter_map_view/ios"
:path: "/Users/ceisufro/AndroidStudioProjects/flutter_google_map_view/ios"

SPEC CHECKSUMS:
Flutter: 9d0fac939486c9aba2809b7982dfdbb47a7b0296
Expand Down
3 changes: 3 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ class _MyAppState extends State<MyApp> {
new MapOptions(
mapViewType: MapViewType.normal,
showUserLocation: true,
showMyLocationButton: true,
showCompassButton: true,
hideToolbar: false,
title: "Recently Visited"),
toolbarActions: [new ToolbarAction("Close", 1)]);
StreamSubscription sub = mapView.onMapReady.listen((_) {
Expand Down
18 changes: 18 additions & 0 deletions flutter_google_map_view.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/.pub" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/example/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/example/.pub" />
<excludeFolder url="file://$MODULE_DIR$/example/build" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Flutter Plugins" level="project" />
</component>
</module>
4 changes: 3 additions & 1 deletion ios/Classes/MapViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
- (NSArray *)visiblePolylines;
- (NSArray *)visiblePolygons;

- (void)setLocationEnabled:(BOOL) enabled;
- (void)setMapOptions:(BOOL)myLocationEnabled
locationButton:(BOOL)myLocationButton
compassButton:(BOOL)compassButton;

@property (readonly) float zoomLevel;
@property (readonly) CLLocationCoordinate2D centerLocation;
Expand Down
26 changes: 16 additions & 10 deletions ios/Classes/MapViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ @interface MapViewController ()
@property (nonatomic, retain) NSMutableArray *polylines;
@property (nonatomic, retain) NSMutableArray *polygons;
@property (nonatomic) BOOL _locationEnabled;
@property (nonatomic) BOOL _locationButton;
@property (nonatomic) BOOL _compassButton;
@property (nonatomic) BOOL observingLocation;
@property (nonatomic, assign) MapViewPlugin *plugin;
@property (nonatomic, retain) NSArray *navigationItems;
Expand Down Expand Up @@ -60,29 +62,33 @@ - (void)viewDidLoad {
self.navigationItem.rightBarButtonItems = self.navigationItems;
}

- (void)setLocationEnabled:(BOOL)enabled {
self._locationEnabled = enabled;
- (void)setMapOptions:(BOOL)myLocationEnabled
locationButton:(BOOL)myLocationButton
compassButton:(BOOL)compassButton{
self._locationEnabled = myLocationEnabled;
self._locationButton = myLocationButton;
self._compassButton = compassButton;
}

- (void) loadMapOptions{
if (self.mapView) {
self.mapView.myLocationEnabled = enabled;
self.mapView.settings.myLocationButton = enabled;
if (enabled) {
self.mapView.settings.compassButton = self._compassButton;
if (self._locationEnabled) {
self.mapView.myLocationEnabled = YES;
self.mapView.settings.myLocationButton = self._locationButton;
[self monitorLocationChanges];
} else {
[self stopMonitoringLocationChanges];
}
}
}

- (void)loadView {
self.mapView = [GMSMapView mapWithFrame:CGRectZero camera:self.initialCameraPosition];
self.view = self.mapView;

// Creates a marker in the center of the map.
self.mapView.delegate = self;
self.mapView.myLocationEnabled = self._locationEnabled;
if (self._locationEnabled) {
[self monitorLocationChanges];
}
[self loadMapOptions];

self.mapView.mapType = self.mapViewType;
[self.plugin onMapReady];
Expand Down
14 changes: 12 additions & 2 deletions ios/Classes/MapViewPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
navigationItems:[self buttonItemsFromActions:args[@"actions"]]
cameraPosition:[self cameraPositionFromDict:cameraDict]];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:vc];
navController.navigationBar.hidden = [mapOptions[@"hideToolbar"] boolValue];
navController.navigationBar.translucent = NO;
[self.host presentViewController:navController animated:true completion:nil];
self.mapViewController = vc;
[self.mapViewController setLocationEnabled:[mapOptions[@"showUserLocation"] boolValue]];
[self.mapViewController setMapOptions:[mapOptions[@"showUserLocation"] boolValue] locationButton:[mapOptions[@"showMyLocationButton"] boolValue] compassButton:[mapOptions[@"showCompassButton"] boolValue]];
result(@YES);
} else if ([@"getVisibleMarkers" isEqualToString:call.method]) {
result(self.mapViewController.visibleMarkers);
Expand Down Expand Up @@ -225,7 +226,16 @@ - (void)onMapReady {
}

- (void)locationDidUpdate:(CLLocation *)location {
[self.channel invokeMethod:@"locationUpdated" arguments:@{@"latitude": @(location.coordinate.latitude), @"longitude": @(location.coordinate.longitude)}];
NSInteger time = location.timestamp.timeIntervalSince1970;
time *= 1000;
[self.channel invokeMethod:@"locationUpdated" arguments:@{@"latitude": @(location.coordinate.latitude),
@"longitude": @(location.coordinate.longitude),
@"time":@(time),
@"altitude":@(location.altitude),
@"speed":@(location.speed),
@"horizontalAccuracy":@(location.horizontalAccuracy),
@"verticalAccuracy":@(location.verticalAccuracy)
}];
}

- (void)annotationTapped:(NSString *)identifier {
Expand Down
25 changes: 23 additions & 2 deletions lib/map_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,22 @@ import 'package:map_view/location.dart';
import 'package:map_view/map_view_type.dart';

class MapOptions {
/// Allows the app to receive location updates.
final bool showUserLocation;
/// Hide/show the button to center the map on the user location.
///
/// Requires showUserLocation to be true.
final bool showMyLocationButton;
/// Hide/show the compass button on the map.
///
/// Normally is not visible all the time. Becomes visible when the orientation
/// of the map is changes through gesture.
final bool showCompassButton;
/// Hide/show the toolbar while on the map activity/view.
///
/// The actions passed to the function show of the MapView will not work
/// because will not be visible.
final bool hideToolbar;
final CameraPosition initialCameraPosition;
final String title;
static const CameraPosition _defaultCamera =
Expand All @@ -12,22 +27,28 @@ class MapOptions {

MapOptions(
{this.showUserLocation: false,
this.showMyLocationButton: false,
this.showCompassButton: false,
this.hideToolbar = false,
this.initialCameraPosition: _defaultCamera,
this.title: "",
this.mapViewType: MapViewType.normal});

Map<String, dynamic> toMap() {
return {
"showUserLocation": showUserLocation,
"showMyLocationButton": showMyLocationButton,
"showCompassButton": showCompassButton,
"hideToolbar": hideToolbar,
"cameraPosition": initialCameraPosition.toMap(),
"title": title,
"mapViewType" : getMapTypeName(mapViewType)
"mapViewType": getMapTypeName(mapViewType)
};
}

String getMapTypeName(MapViewType mapType) {
String mapTypeName = "normal";
switch(mapType) {
switch (mapType) {
case MapViewType.none:
mapTypeName = "none";
break;
Expand Down
1 change: 1 addition & 0 deletions lib/map_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class MapView {
if (toolbarActions != null) {
actions = toolbarActions.map((t) => t.toMap).toList();
}
print(mapOptions.toMap());
_channel.invokeMethod(
'show', {"mapOptions": mapOptions.toMap(), "actions": actions});
}
Expand Down

0 comments on commit d3407b4

Please sign in to comment.