-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added google geocoding to get city/state/country #83
Open
oianmol
wants to merge
12
commits into
designs_v1.1
Choose a base branch
from
DEV-211
base: designs_v1.1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
07e7398
added google geocoding to get city/state/country
anmolvermamm 9209333
Airtable API Integration, Also adds DotEnv for API Keys
tsjamm 8bbbfb1
fixes a decoding issue
tsjamm 511762b
Fixes Handling Airtable Response Data
tsjamm 28da6d6
remove location from user api and check for location gate in location…
anmolvermamm c0eb2a2
Changes API to return true or false for a location string
tsjamm 6b600c1
add location to user API
anmolvermamm a3edc8a
Fixes a bug in query
tsjamm 6599478
Merge branch 'DEV-211' into airtable-integration
anmolvermamm fb34a77
Merge pull request #84 from Corona-Trace/airtable-integration
oianmol 960f8ba
check with city if location gate available
anmolvermamm 1237d3d
disable minification because build failing
anmolvermamm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,12 @@ import 'package:corona_trace/network/notification/response_notification.dart'; | |
import 'package:dio/dio.dart'; | ||
import 'package:flutter_background_geolocation/flutter_background_geolocation.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:google_geocoding/google_geocoding.dart' as GoogleGeo; | ||
import 'package:http/http.dart' as http; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
|
||
import '../app_constants.dart'; | ||
|
||
class ApiRepository { | ||
static final ApiRepository _instance = ApiRepository._internal(); | ||
|
||
|
@@ -43,8 +46,7 @@ class ApiRepository { | |
var deviceID = await AppConstants.getDeviceId(); | ||
var url = "$API_URL/users"; | ||
var body = tokenRequestBody(token, deviceID, currentLocation); | ||
Response response = | ||
await _dio.post(url, data: JSON.jsonEncode(body)); | ||
Response response = await _dio.post(url, data: JSON.jsonEncode(body)); | ||
var statusCode = response.statusCode; | ||
debugPrint("$statusCode - $url"); | ||
if (response.statusCode == 200) { | ||
|
@@ -54,9 +56,48 @@ class ApiRepository { | |
return false; | ||
} | ||
|
||
static Map<String, dynamic> tokenRequestBody(String token, String deviceID, Location location) => | ||
{ | ||
"token": token, | ||
static Future<bool> isExistsInLocationGate(Location fromLocation) async { | ||
try { | ||
GoogleGeo.GoogleGeocoding googleGeocoding = | ||
GoogleGeo.GoogleGeocoding(AppConstants.API_KEY_GEOCODING); | ||
var geocodingResponse = await googleGeocoding.geocoding.getReverse( | ||
GoogleGeo.LatLon( | ||
fromLocation.coords.latitude, fromLocation.coords.longitude)); | ||
var address = geocodingResponse.results.first.addressComponents; | ||
Triple csc = extractCSC(address); | ||
return true; | ||
} catch (ex) { | ||
print(ex); | ||
} | ||
return false; | ||
} | ||
|
||
static Triple extractCSC(List<GoogleGeo.AddressComponent> address) { | ||
var country; | ||
var state; | ||
var city; | ||
if (address.isNotEmpty) { | ||
address.forEach((addressComponent) { | ||
addressComponent.types.forEach((type) { | ||
if (type == "country") { | ||
country = addressComponent.longName; | ||
} | ||
if (type == "administrative_area_level_1") { | ||
state = addressComponent.longName; | ||
} | ||
if (type == "locality") { | ||
city = addressComponent.longName; | ||
} | ||
}); | ||
}); | ||
} | ||
return Triple(country, state, city); | ||
} | ||
|
||
static Map<String, dynamic> tokenRequestBody(String token, String deviceID, | ||
Location location) => | ||
{ | ||
"token": token, | ||
"userId": deviceID, | ||
"location": { | ||
"latitude": location.coords.latitude, | ||
|
@@ -162,3 +203,11 @@ class ApiRepository { | |
await sharedPrefs.setBool(DID_ALLOW_NOTIFY_WHEN_AVAILABLE, shouldNotify); | ||
} | ||
} | ||
|
||
class Triple<T extends String, S extends String, C extends String> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice name 😅 How about LocationGateTriple |
||
T a; | ||
S b; | ||
C c; | ||
|
||
Triple(this.a, this.b, this.c); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will move to .env I guess