Skip to content

Commit

Permalink
renamed example, added mobile and web preferences of map, migrated fr…
Browse files Browse the repository at this point in the history
…om Rectangle to GeoCoordBounds, added more customization to the map
  • Loading branch information
OlehMarch committed Mar 4, 2020
1 parent 67bccfd commit 1c50880
Show file tree
Hide file tree
Showing 22 changed files with 335 additions and 93 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ void main() {



## Feature requests
## Feature requests and Bug reports

Feel free to post feature requests [here](https://github.com/marchdev-tk/flinq/issues).
Feel free to post a feature requests or report a bug [here](https://github.com/marchdev-tk/flutter_google_maps/issues).

## TODO

* Add circles support
* Add polyline support
Binary file removed assets/images/map-marker-warehouse.png
Binary file not shown.
25 changes: 24 additions & 1 deletion example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter_google_maps/flutter_google_maps.dart';
void main() {
GoogleMap.init('AIzaSyAaiBfE-fMdqesFZwktXk5hnkfaZQ-HWPg');
GoogleMap.init('API_KEY');
WidgetsFlutterBinding.ensureInitialized();
runApp(MyApp());
}
Expand Down Expand Up @@ -135,6 +135,29 @@ class _MyHomePageState extends State<MyHomePage> {
Positioned.fill(
child: GoogleMap(
key: _key,
initialZoom: 12,
initialPosition:
GeoCoord(34.0469058, -118.3503948), // Los Angeles, CA
mapType: MapType.terrain,
mobilePreferences: const MobileMapPreferences(
trafficEnabled: true,
),
webPreferences: WebMapPreferences(
fullscreenControl: true,
),
),
),
Positioned(
top: 16,
left: 16,
child: FloatingActionButton(
child: Icon(Icons.person_pin_circle),
onPressed: () {
GoogleMap.of(_key).moveCamera(GeoCoordBounds(
northeast: GeoCoord(34.021307, -117.432317),
southwest: GeoCoord(33.835745, -117.712785),
));
},
),
),
Positioned(
Expand Down
4 changes: 1 addition & 3 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ android {
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.example"
applicationId "marchdev.tk.flutter_google_maps_example"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
Expand All @@ -48,7 +47,6 @@ android {

buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
Expand Down
2 changes: 1 addition & 1 deletion example/android/app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.example">
package="marchdev.tk.flutter_google_maps_example">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
Expand Down
4 changes: 2 additions & 2 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.example">
package="marchdev.tk.flutter_google_maps_example">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="example"
android:label="flutter_google_maps_example"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.example
package marchdev.tk.flutter_google_maps_example

import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity
Expand Down
2 changes: 1 addition & 1 deletion example/android/app/src/profile/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.example">
package="marchdev.tk.flutter_google_maps_example">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
Expand Down
6 changes: 3 additions & 3 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
PRODUCT_BUNDLE_IDENTIFIER = com.example.example;
PRODUCT_BUNDLE_IDENTIFIER = marchdev.tk.flutter_google_maps_example;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
Expand Down Expand Up @@ -454,7 +454,7 @@
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
PRODUCT_BUNDLE_IDENTIFIER = com.example.example;
PRODUCT_BUNDLE_IDENTIFIER = marchdev.tk.flutter_google_maps_example;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -481,7 +481,7 @@
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
PRODUCT_BUNDLE_IDENTIFIER = com.example.example;
PRODUCT_BUNDLE_IDENTIFIER = marchdev.tk.flutter_google_maps_example;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>example</string>
<string>flutter_google_maps_example</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
Expand Down
23 changes: 23 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,29 @@ class _MyHomePageState extends State<MyHomePage> {
Positioned.fill(
child: GoogleMap(
key: _key,
initialZoom: 12,
initialPosition:
GeoCoord(34.0469058, -118.3503948), // Los Angeles, CA
mapType: MapType.terrain,
mobilePreferences: const MobileMapPreferences(
trafficEnabled: true,
),
webPreferences: WebMapPreferences(
fullscreenControl: true,
),
),
),
Positioned(
top: 16,
left: 16,
child: FloatingActionButton(
child: Icon(Icons.person_pin_circle),
onPressed: () {
GoogleMap.of(_key).moveCamera(GeoCoordBounds(
northeast: GeoCoord(34.021307, -117.432317),
southwest: GeoCoord(33.835745, -117.712785),
));
},
),
),
Positioned(
Expand Down
2 changes: 1 addition & 1 deletion example/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="UTF-8">
<title>example</title>
<title>flutter_google_maps_example</title>
</head>
<body>
<script src="https://maps.googleapis.com/maps/api/js?key=API_KEY"></script>
Expand Down
3 changes: 3 additions & 0 deletions lib/flutter_google_maps.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
library flutter_google_maps;

export 'src/core/map_operations.dart';
export 'src/core/map_preferences.dart';

export 'src/core/google_map.dart';
export 'src/core/google_map.state.dart'
if (dart.library.html) 'src/web/google_map.state.dart'
if (dart.library.io) 'src/mobile/google_map.state.dart';

export 'package:google_polyline_algorithm/google_polyline_algorithm.dart';
export 'package:google_directions_api/google_directions_api.dart'
show GeoCoord, GeoCoordBounds;
50 changes: 41 additions & 9 deletions lib/src/core/google_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

import 'package:flutter/widgets.dart';
import 'package:flutter/foundation.dart';
import 'package:google_directions_api/google_directions_api.dart';

import 'package:google_directions_api/google_directions_api.dart'
show GeoCoord, DirectionsService;

import 'map_operations.dart';
import 'map_preferences.dart';

import 'google_map.state.dart'
if (dart.library.html) '../web/google_map.state.dart'
Expand All @@ -16,16 +19,45 @@ import 'google_map.state.dart'
class GoogleMap extends StatefulWidget {
const GoogleMap({
Key key,
this.lat = defaultLat,
this.lng = defaultLng,
}) : super(key: key);
this.minZoom,
this.maxZoom,
this.initialZoom = _zoom,
this.mapType = MapType.normal,
this.initialPosition = const GeoCoord(_defaultLat, _defaultLng),
this.mobilePreferences = const MobileMapPreferences(),
this.webPreferences = const WebMapPreferences(),
}) : assert(mapType != null),
assert(mapType != null),
assert(initialPosition != null),
assert(initialZoom != null),
assert(mobilePreferences != null),
assert(webPreferences != null),
super(key: key);

/// The initial position of the map's camera.
final GeoCoord initialPosition;

/// The initial zoom of the map's camera.
final double initialZoom;

/// Type of map tiles to be rendered.
final MapType mapType;

/// The preferred minimum zoom level or null, if unbounded from below.
final double minZoom;

/// The preferred maximum zoom level or null, if unbounded from above.
final double maxZoom;

/// Set of mobile map preferences
final MobileMapPreferences mobilePreferences;

final double lat;
final double lng;
/// Set of web map preferences
final WebMapPreferences webPreferences;

static const defaultLat = 34.0469058;
static const defaultLng = -118.3503948;
static const zoom = 12;
static const _zoom = 12.0;
static const _defaultLat = 34.0469058;
static const _defaultLng = -118.3503948;

static MapOperations of(GlobalKey<GoogleMapStateBase> key) =>
key.currentState;
Expand Down
5 changes: 4 additions & 1 deletion lib/src/core/google_map.state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import 'dart:math';

import 'package:flutter/widgets.dart';

import 'package:google_directions_api/google_directions_api.dart'
show GeoCoordBounds;

import 'google_map.dart';

class GoogleMapState extends GoogleMapStateBase {
@override
void moveCamera(
Rectangle<double> newBounds, {
GeoCoordBounds newBounds, {
double padding = 0,
bool animated = true,
}) =>
Expand Down
8 changes: 6 additions & 2 deletions lib/src/core/map_operations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
// BSD-style license that can be found in the LICENSE file.

import 'dart:ui' show Color;
import 'dart:math' show Point, Rectangle;
import 'dart:math' show Point;

import 'package:google_directions_api/google_directions_api.dart'
show GeoCoordBounds;

abstract class MapOperations
implements MapMarkers, MapDirections, MapPolygones {
/// Moves camera to the new bounds.
void moveCamera(
Rectangle<double> newBounds, {
GeoCoordBounds newBounds, {
double padding = 0,
bool animated = true,
});
Expand Down
Loading

0 comments on commit 1c50880

Please sign in to comment.