Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
bazrafkan committed Apr 3, 2020
0 parents commit 4460f63
Show file tree
Hide file tree
Showing 52 changed files with 2,105 additions and 0 deletions.
75 changes: 75 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
build/

# Android related
**/android/**/gradle-wrapper.jar
**/android/.gradle
**/android/captures/
**/android/gradlew
**/android/gradlew.bat
**/android/local.properties
**/android/**/GeneratedPluginRegistrant.java

# iOS/XCode related
**/ios/**/*.mode1v3
**/ios/**/*.mode2v3
**/ios/**/*.moved-aside
**/ios/**/*.pbxuser
**/ios/**/*.perspectivev3
**/ios/**/*sync/
**/ios/**/.sconsign.dblite
**/ios/**/.tags*
**/ios/**/.vagrant/
**/ios/**/DerivedData/
**/ios/**/Icon?
**/ios/**/Pods/
**/ios/**/.symlinks/
**/ios/**/profile
**/ios/**/xcuserdata
**/ios/.generated/
**/ios/Flutter/App.framework
**/ios/Flutter/Flutter.framework
**/ios/Flutter/Flutter.podspec
**/ios/Flutter/Generated.xcconfig
**/ios/Flutter/app.flx
**/ios/Flutter/app.zip
**/ios/Flutter/flutter_assets/
**/ios/Flutter/flutter_export_environment.sh
**/ios/ServiceDefinitions.json
**/ios/Runner/GeneratedPluginRegistrant.*

# Exceptions to above rules.
!**/ios/**/default.mode1v3
!**/ios/**/default.mode2v3
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
10 changes: 10 additions & 0 deletions .metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: 2294d75bfa8d067ba90230c0fc2268f3636d7584
channel: beta

project_type: package
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## [0.0.1] - 2020-04-02

- The initial release supports all google place api requests
- Place Search returns a list of places based on a user's location or search string.
- Place Details returns more detailed information about a specific place, including user reviews.
- Place Photos provides access to the millions of place-related photos stored in Google's Place database.
- Place Autocomplete automatically fills in the name and/or address of a place as users type.
- Query Autocomplete provides a query prediction service for text-based geographic searches, returning suggested queries as users type.
22 changes: 22 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Contributing to the google_place package.
Thank you for your interest in contributing to the ***google_place*** package! I love receiving contributions, and your work helps quality of this package. This doc will walk you through the easiest way to make a change and have it submitted to the ***google_place*** package.

## Developer workflow
The easiest workflow for adding a feature/fixing a bug is to test it out on the example app in this repo.

### Environment
1. Fork the ***google_place*** repo on github.
2. Clone your fork of the ***google_place*** repo.
3. Build and run the example app in example/lib/main.dart (from the example/ directory, use $ flutter run).

### Development
1. Make the changes to your local copy of the ***google_place*** package, testing the changes in the example app.
2. Write a unit test for your change, if possible, in one of the files in test/.
3. Update the CHANGELOG.md with a new version number, and a description of the change you're making.
4. Update the version: in the pubspec.yaml file to your new version.

### Review
1. Make sure all the existing tests are passing by using the following command (from the root of the project): $ flutter test test/.
2. Make sure the repo is formatted using $ flutter format ..
3. Create a PR to merge the branch on your fork into ***google_place/master***.
4. Add bazrafkan as reviewers on the PR. I will take a look and add any comments. When the PR is ready to be merged, I will merge it and update the package on pub.dev!
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 bazrafkan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# google_place

A Flutter plugin that provides a [Google Place API](https://developers.google.com/places/web-service/intro).

## Preview

The Places API is a service that returns information about places using HTTP requests. Places are defined within this API as establishments, geographic locations, or prominent points of interest.

The following place requests are available:

1. [Place Search](https://developers.google.com/places/web-service/search) returns a list of places based on a user's location or search string.
2. [Place Details](https://developers.google.com/places/web-service/details) returns more detailed information about a specific place, including user reviews.
3. [Place Photos](https://developers.google.com/places/web-service/photos) provides access to the millions of place-related photos stored in Google's Place database.
4. [Place Autocomplete](https://developers.google.com/places/web-service/autocomplete) automatically fills in the name and/or address of a place as users type.
5. [Query Autocomplete](https://developers.google.com/places/web-service/query) provides a query prediction service for text-based geographic searches, returning suggested queries as users type.

## Usage

To use this plugin, add **_google_place_** as a [dependency in your pubspec.yaml file](https://flutter.dev/docs/development/packages-and-plugins/using-packages).

## Getting Started

- Get an API key at [https://cloud.google.com/maps-platform/](https://cloud.google.com/maps-platform/).
- Go to Google Developers Console.
- Choose the project that you want to enable Google Place on.

## Sample Usage

```dart
var googlePlace = GooglePlace("Your-Key");
var risult = await googlePlace.autocomplete.get("1600 Amphitheatre");
```
31 changes: 31 additions & 0 deletions lib/google_place.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
library google_place;

import 'package:google_place/src/autocomplete/autocomplete.dart';
import 'package:google_place/src/details/details.dart';
import 'package:google_place/src/photos/photos.dart';
import 'package:google_place/src/query_autocomplete/query_autocomplete.dart';
import 'package:google_place/src/search/search.dart';

export 'package:google_place/src/autocomplete/autocomplete_result.dart';
export 'package:google_place/src/models/input_type.dart';
export 'package:google_place/src/models/lat_lng.dart';
export 'package:google_place/src/models/locationbias.dart';
export 'package:google_place/src/search/find_place_result.dart';

class GooglePlace {
final String apiKEY;
Search search;
Details details;
Photos photos;
Autocomplete autocomplete;
QueryAutocomplete queryAutocomplete;

GooglePlace(this.apiKEY) {
assert(apiKEY != null);
this.search = Search(apiKEY);
this.details = Details(apiKEY);
this.photos = Photos(apiKEY);
this.autocomplete = Autocomplete(apiKEY);
this.queryAutocomplete = QueryAutocomplete(apiKEY);
}
}
54 changes: 54 additions & 0 deletions lib/src/autocomplete/autocomplete.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import 'package:google_place/src/autocomplete/autocomplete_parameters.dart';
import 'package:google_place/src/autocomplete/autocomplete_result.dart';
import 'package:google_place/src/models/lat_lng.dart';
import 'package:google_place/src/utils/network_utility.dart';

class Autocomplete {
final _authority = 'maps.googleapis.com';
final _unencodedPath = 'maps/api/place/autocomplete/json';
final String apiKEY;

Autocomplete(this.apiKEY);

/// Create a deprecation annotation which specifies the migration path and
/// expiration of the annotated feature.
///
/// The [input] argument should be readable by programmers, and should state
/// an alternative feature (if available) as well as when an annotated feature
/// is expected to be removed.
Future<AutocompleteResult> get(
String input, {
String sessionToken,
int offset,
LatLng origin,
LatLng location,
int radius,
String language,
String types,
List<String> components,
bool strictbounds = false,
}) async {
assert(input != null);
assert(input != "");
if (strictbounds) {
assert(location != null);
assert(radius != null);
}
var queryParameters = AutocompleteParameters.createParameters(
apiKEY,
input,
sessionToken,
offset,
origin,
location,
radius,
language,
types,
components,
strictbounds,
);
var uri = Uri.https(_authority, _unencodedPath, queryParameters);
var response = await NetworkUtility.fetchUrl(uri);
return AutocompleteResult.parseAutocompleteResult(response);
}
}
98 changes: 98 additions & 0 deletions lib/src/autocomplete/autocomplete_parameters.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import 'package:google_place/src/models/lat_lng.dart';

class AutocompleteParameters {
static Map<String, String> createParameters(
String apiKEY,
String input,
String sessionToken,
int offset,
LatLng origin,
LatLng location,
int radius,
String language,
String types,
List<String> components,
bool strictbounds,
) {
String result = input.trimRight();
result = result.trimLeft();
Map<String, String> queryParameters = {
'input': result,
'key': apiKEY,
};

String componentsQuery;
if (components != null) {
for (int i = 0; i < components.length; i++) {
componentsQuery += 'country:${components[i]}';
if (i + 1 != components.length) {
componentsQuery += '|';
}
}
}

if (origin != null) {
var item = {
'origin': '${origin.latitude},${origin.latitude}',
};
queryParameters.addAll(item);
}

if (location != null) {
var item = {
'location': '${location.latitude},${location.latitude}',
};
queryParameters.addAll(item);
}

if (offset != null) {
var item = {
'offset': offset.toString(),
};
queryParameters.addAll(item);
}

if (radius != null) {
var item = {
'radius': radius.toString(),
};
queryParameters.addAll(item);
}

if (sessionToken != null && sessionToken != '') {
var item = {
'sessionToken': sessionToken,
};
queryParameters.addAll(item);
}

if (language != null && language != '') {
var item = {
'language': language,
};
queryParameters.addAll(item);
}

if (types != null && types != '') {
var item = {
'types': types,
};
queryParameters.addAll(item);
}

if (strictbounds) {
var item = {
'strictbounds': 'strictbounds',
};
queryParameters.addAll(item);
}

if (componentsQuery != null && componentsQuery != '') {
var item = {
'components': componentsQuery,
};
queryParameters.addAll(item);
}
return queryParameters;
}
}
26 changes: 26 additions & 0 deletions lib/src/autocomplete/autocomplete_result.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'dart:convert';

import 'package:google_place/src/autocomplete/prediction.dart';

class AutocompleteResult {
final String status;
final List<Prediction> predictions;

AutocompleteResult({this.status, this.predictions});

factory AutocompleteResult.fromJson(Map<String, dynamic> json) {
return AutocompleteResult(
status: json['status'] as String,
predictions: json['predictions'] != null
? json['predictions']
.map<Prediction>((json) => Prediction.fromJson(json))
.toList()
: null,
);
}

static AutocompleteResult parseAutocompleteResult(String responseBody) {
final parsed = json.decode(responseBody).cast<String, dynamic>();
return AutocompleteResult.fromJson(parsed);
}
}
Loading

0 comments on commit 4460f63

Please sign in to comment.