Merge branch 'development' of https://gitlab.com/Cloud_Solution/diplomatic-quarter into my_tracker
Conflicts: lib/config/localized_values.dartmerge-requests/248/head
commit
f883e1bd78
@ -1,13 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
package com.cloud.diplomaticquarterapp.geofence
|
|
||||||
|
|
||||||
import android.content.BroadcastReceiver
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
|
||||||
|
|
||||||
class GeofenceBroadcastReceiver : BroadcastReceiver() {
|
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
|
||||||
GeofenceTransitionsJobIntentService.enqueueWork(context, intent)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,49 @@
|
|||||||
|
|
||||||
|
|
||||||
|
package com.cloud.diplomaticquarterapp.geofence.intent_receivers
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.util.Log
|
||||||
|
import com.cloud.diplomaticquarterapp.geofence.GeofenceTransition
|
||||||
|
import com.cloud.diplomaticquarterapp.geofence.HMG_Geofence
|
||||||
|
import com.cloud.diplomaticquarterapp.utils.Logs
|
||||||
|
import com.google.android.gms.location.GeofenceStatusCodes
|
||||||
|
import com.google.android.gms.location.GeofencingEvent
|
||||||
|
|
||||||
|
class GeofenceBroadcastReceiver : BroadcastReceiver() {
|
||||||
|
private val LOG_TAG = "GeofenceBroadcastReceiver"
|
||||||
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
|
||||||
|
val geofencingEvent = GeofencingEvent.fromIntent(intent)
|
||||||
|
if (geofencingEvent.hasError()) {
|
||||||
|
val errorMessage = GeofenceErrorMessages.getErrorString(context, geofencingEvent.errorCode)
|
||||||
|
Log.e(LOG_TAG, errorMessage)
|
||||||
|
|
||||||
|
Logs.GeofenceEvent.save(context,LOG_TAG,"Error while triggering geofence event",Logs.STATUS.ERROR)
|
||||||
|
doReRegisterIfRequired(context,geofencingEvent.errorCode)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
Logs.GeofenceEvent.save(context,LOG_TAG,"Geofence event triggered: ${GeofenceTransition.fromInt(geofencingEvent.geofenceTransition).value} for ${geofencingEvent.triggeringGeofences.map {it.requestId}}",Logs.STATUS.SUCCESS)
|
||||||
|
HMG_Geofence.shared(context).handleEvent(geofencingEvent.triggeringGeofences,geofencingEvent.triggeringLocation, GeofenceTransition.fromInt(geofencingEvent.geofenceTransition));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun doReRegisterIfRequired(context: Context, errorCode: Int){
|
||||||
|
val errorRequiredReregister = listOf(
|
||||||
|
GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE,
|
||||||
|
GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES,
|
||||||
|
GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS,
|
||||||
|
GeofenceStatusCodes.GEOFENCE_REQUEST_TOO_FREQUENT
|
||||||
|
)
|
||||||
|
|
||||||
|
if(errorRequiredReregister.contains(errorCode))
|
||||||
|
HMG_Geofence.shared(context).register(){ status, error ->
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
|
||||||
|
package com.cloud.diplomaticquarterapp.geofence.intent_receivers
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import com.cloud.diplomaticquarterapp.geofence.HMG_Geofence
|
||||||
|
import com.google.android.gms.location.GeofenceStatusCodes
|
||||||
|
|
||||||
|
class GeofenceBroadcastReceiverWithJobService : BroadcastReceiver() {
|
||||||
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
GeofenceTransitionsJobIntentService.enqueueWork(context, intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,26 +1,22 @@
|
|||||||
|
|
||||||
|
|
||||||
package com.cloud.diplomaticquarterapp.geofence
|
package com.cloud.diplomaticquarterapp.geofence.intent_receivers
|
||||||
|
|
||||||
import android.content.BroadcastReceiver
|
import android.content.BroadcastReceiver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Handler
|
|
||||||
import android.os.Message
|
|
||||||
import com.cloud.diplomaticquarterapp.geofence.HMG_Geofence
|
import com.cloud.diplomaticquarterapp.geofence.HMG_Geofence
|
||||||
import com.cloud.diplomaticquarterapp.utils.HMGUtils
|
import com.cloud.diplomaticquarterapp.utils.PREFS_STORAGE
|
||||||
|
|
||||||
class GeofencingRebootBroadcastReceiver : BroadcastReceiver(){
|
class GeofencingRebootBroadcastReceiver : BroadcastReceiver(){
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
|
||||||
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.action)) {
|
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.action)) {
|
||||||
|
// if (intent.action.equals("android.intent.action.BOOT_COMPLETE")) {
|
||||||
val pref = context.getSharedPreferences(PREFS_STORAGE, Context.MODE_PRIVATE)
|
val pref = context.getSharedPreferences(PREFS_STORAGE, Context.MODE_PRIVATE)
|
||||||
pref.edit().putString("REBOOT_DETECTED","YES").apply()
|
pref.edit().putString("REBOOT_DETECTED","YES").apply()
|
||||||
|
|
||||||
HMG_Geofence.shared(context).unRegisterAll { status, exception ->
|
HMG_Geofence.shared(context).register(){ status, error -> }
|
||||||
val geoZones = HMGUtils.getGeoZonesFromPreference(context)
|
|
||||||
HMG_Geofence.shared(context).register(geoZones)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
|
||||||
|
package com.cloud.diplomaticquarterapp.geofence.intent_receivers
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.location.LocationManager
|
||||||
|
import com.cloud.diplomaticquarterapp.geofence.HMG_Geofence
|
||||||
|
import com.cloud.diplomaticquarterapp.utils.HMGUtils
|
||||||
|
import com.cloud.diplomaticquarterapp.utils.PREFS_STORAGE
|
||||||
|
|
||||||
|
class LocationProviderChangeReceiver : BroadcastReceiver() {
|
||||||
|
private val LOG_TAG = "LocationProviderChangeReceiver"
|
||||||
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
|
||||||
|
if (LocationManager.PROVIDERS_CHANGED_ACTION.equals(intent.action)) {
|
||||||
|
val pref = context.getSharedPreferences(PREFS_STORAGE, Context.MODE_PRIVATE)
|
||||||
|
pref.edit().putString("LOCATION_PROVIDER_CHANGE","YES").apply()
|
||||||
|
|
||||||
|
HMG_Geofence.shared(context).register(){ s, e -> }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
package com.cloud.diplomaticquarterapp.geofence.intent_receivers
|
||||||
|
|
||||||
|
import android.app.job.JobParameters
|
||||||
|
import android.app.job.JobService
|
||||||
|
import com.cloud.diplomaticquarterapp.geofence.HMG_Geofence
|
||||||
|
import com.cloud.diplomaticquarterapp.utils.Logs
|
||||||
|
|
||||||
|
class ReregisterGeofenceJobService : JobService(){
|
||||||
|
companion object{
|
||||||
|
val TriggerIntervalDuration:String = "06:00:00"
|
||||||
|
val JobID = 918273
|
||||||
|
}
|
||||||
|
override fun onStartJob(params: JobParameters?): Boolean {
|
||||||
|
Logs.save(applicationContext,"ReregisterGeofenceJobService.onStartJob", "triggered to re-register the geofences after $TriggerIntervalDuration >> [HH:mm:ss]")
|
||||||
|
HMG_Geofence.shared(applicationContext).register(){ status, error ->
|
||||||
|
jobFinished(params, true)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStopJob(params: JobParameters?): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
package com.cloud.diplomaticquarterapp.utils
|
||||||
|
|
||||||
|
|
||||||
|
const val PREFS_STORAGE = "FlutterSharedPreferences"
|
||||||
|
const val PREF_KEY_SUCCESS = "HMG_GEOFENCE_SUCCESS"
|
||||||
|
const val PREF_KEY_FAILED = "HMG_GEOFENCE_FAILED"
|
||||||
|
const val PREF_KEY_HMG_ZONES = "flutter.hmg-geo-fences"
|
||||||
|
const val PREF_KEY_LANGUAGE = "flutter.language"
|
||||||
@ -0,0 +1,145 @@
|
|||||||
|
package com.cloud.diplomaticquarterapp.utils
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.SharedPreferences
|
||||||
|
import android.os.Build
|
||||||
|
import com.cloud.diplomaticquarterapp.BuildConfig
|
||||||
|
import com.google.gson.Gson
|
||||||
|
|
||||||
|
class Logs {
|
||||||
|
|
||||||
|
enum class STATUS{
|
||||||
|
SUCCESS,
|
||||||
|
ERROR;
|
||||||
|
}
|
||||||
|
class GeofenceEvent{
|
||||||
|
companion object{
|
||||||
|
fun save(context: Context, tag:String, message:String, status:Logs.STATUS = STATUS.SUCCESS){
|
||||||
|
Logs.Common.save(context,"GeofenceEvent", tag, message, status)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun list(context: Context, tag:String? = null, status:Logs.STATUS? = null):List<LogModel>{
|
||||||
|
return Logs.Common.list(context,"GeofenceEvent", tag, status)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun raw(context: Context):String{
|
||||||
|
return Logs.Common.raw(context,"GeofenceEvent")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RegisterGeofence{
|
||||||
|
companion object{
|
||||||
|
fun save(context: Context, tag:String, message:String, status:Logs.STATUS = STATUS.SUCCESS){
|
||||||
|
Logs.Common.save(context,"RegisterGeofence", tag, message, status)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun list(context: Context, tag:String? = null, status:Logs.STATUS? = null):List<LogModel>{
|
||||||
|
return Logs.Common.list(context,"RegisterGeofence", tag, status)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun raw(context: Context):String{
|
||||||
|
return Logs.Common.raw(context,"RegisterGeofence");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
companion object{
|
||||||
|
private var pref:SharedPreferences? = null
|
||||||
|
fun save(context: Context, tag:String, message:String, status:Logs.STATUS = STATUS.SUCCESS){
|
||||||
|
Logs.Common.save(context,"Logs", tag, message, status)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun list(context: Context, tag:String? = null, status:Logs.STATUS? = null):List<LogModel>{
|
||||||
|
return Logs.Common.list(context,"Logs", tag, status)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun raw(context: Context):String{
|
||||||
|
return Logs.Common.raw(context,"Logs");
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun storage(context: Context):SharedPreferences{
|
||||||
|
if(pref == null) {
|
||||||
|
pref = context.getSharedPreferences(PREFS_STORAGE, Context.MODE_PRIVATE)
|
||||||
|
}
|
||||||
|
return pref!!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class Common{
|
||||||
|
companion object{
|
||||||
|
private val gson = Gson()
|
||||||
|
|
||||||
|
fun save(context: Context, key:String, tag:String, message:String, status:Logs.STATUS = STATUS.SUCCESS){
|
||||||
|
if(!BuildConfig.DEBUG)
|
||||||
|
return
|
||||||
|
|
||||||
|
val pref = Logs.storage(context)
|
||||||
|
|
||||||
|
val string = pref.getString(key,"{}")
|
||||||
|
val json = gson.fromJson<LogsContainerModel>(string,LogsContainerModel::class.java)
|
||||||
|
json.add(
|
||||||
|
LogModel().apply {
|
||||||
|
this.TAG = tag
|
||||||
|
this.MESSAGE = message
|
||||||
|
this.STATUS = status.name
|
||||||
|
this.DATE = DateUtils.dateTimeNow()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
pref.edit().putString(key,gson.toJson(json)).apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun list(context: Context, key:String, tag:String? = null, status:Logs.STATUS? = null):List<LogModel>{
|
||||||
|
val pref = Logs.storage(context)
|
||||||
|
val string = pref.getString(key,"{}")
|
||||||
|
val json = gson.fromJson<LogsContainerModel>(string,LogsContainerModel::class.java)
|
||||||
|
if(tag == null && status == null) {
|
||||||
|
return json.LOGS
|
||||||
|
}else if(tag != null && status != null){
|
||||||
|
return json.LOGS.filter { (it.TAG == tag && it.STATUS == status.name) }
|
||||||
|
}else if(tag != null){
|
||||||
|
return json.LOGS.filter { (it.TAG == tag) }
|
||||||
|
}else if(status != null){
|
||||||
|
return json.LOGS.filter { (it.STATUS == status.name) }
|
||||||
|
}
|
||||||
|
return listOf()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun raw(context: Context, key:String):String{
|
||||||
|
val pref = Logs.storage(context)
|
||||||
|
val string = pref.getString(key,"{}")
|
||||||
|
return string!!
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class LogModel{
|
||||||
|
lateinit var TAG:String
|
||||||
|
lateinit var MESSAGE:String
|
||||||
|
lateinit var STATUS:String
|
||||||
|
lateinit var DATE:String
|
||||||
|
|
||||||
|
companion object{
|
||||||
|
fun with(tag:String, message:String, status:String):LogModel{
|
||||||
|
return LogModel().apply {
|
||||||
|
this.TAG = tag
|
||||||
|
this.MESSAGE = message
|
||||||
|
this.STATUS = status
|
||||||
|
this.DATE = DateUtils.dateTimeNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class LogsContainerModel{
|
||||||
|
var LOGS = mutableListOf<LogModel>()
|
||||||
|
fun add(log:LogModel){
|
||||||
|
LOGS.add(log)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 4.9 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 5.2 KiB |
@ -0,0 +1,36 @@
|
|||||||
|
//
|
||||||
|
// FlutterConstants.swift
|
||||||
|
// Runner
|
||||||
|
//
|
||||||
|
// Created by ZiKambrani on 22/12/2020.
|
||||||
|
//
|
||||||
|
|
||||||
|
import UIKit
|
||||||
|
|
||||||
|
class FlutterConstants{
|
||||||
|
static var LOG_GEOFENCE_URL:String?
|
||||||
|
static var WIFI_CREDENTIALS_URL:String?
|
||||||
|
static var DEFAULT_HTTP_PARAMS:[String:Any?]?
|
||||||
|
|
||||||
|
class func set(){
|
||||||
|
|
||||||
|
// (FiX) Take a start with FlutterMethodChannel (kikstart)
|
||||||
|
/* First call to flutter method is not returning the correct value (Always returning 'NSObject') then after it wroking fine and returning correct value*/
|
||||||
|
FlutterText.with(key: "test") { (test) in
|
||||||
|
|
||||||
|
flutterMethodChannel?.invokeMethod("getDefaultHttpParameters", arguments: nil){ (response) in
|
||||||
|
if let defaultHTTPParams = response as? [String:Any?]{
|
||||||
|
DEFAULT_HTTP_PARAMS = defaultHTTPParams
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
flutterMethodChannel?.invokeMethod("getLogGeofenceFullUrl", arguments:nil){ (response) in
|
||||||
|
if let url = response as? String{
|
||||||
|
LOG_GEOFENCE_URL = url
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
@ -0,0 +1,211 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:diplomaticquarterapp/config/config.dart';
|
||||||
|
import 'package:diplomaticquarterapp/core/model/pharmacies/order_model.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_polyline_points/flutter_polyline_points.dart';
|
||||||
|
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||||
|
import 'package:location/location.dart';
|
||||||
|
|
||||||
|
|
||||||
|
class TrackDriver extends StatefulWidget {
|
||||||
|
final OrderModel order;
|
||||||
|
TrackDriver({this.order});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<TrackDriver> createState() => _TrackDriverState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _TrackDriverState extends State<TrackDriver> {
|
||||||
|
OrderModel _order;
|
||||||
|
|
||||||
|
Completer<GoogleMapController> _controller = Completer();
|
||||||
|
|
||||||
|
|
||||||
|
double CAMERA_ZOOM = 16;
|
||||||
|
double CAMERA_TILT = 0;
|
||||||
|
double CAMERA_BEARING = 30;
|
||||||
|
LatLng SOURCE_LOCATION = null;
|
||||||
|
LatLng DEST_LOCATION = null;
|
||||||
|
|
||||||
|
// for my drawn routes on the map
|
||||||
|
Set<Polyline> _polylines = Set<Polyline>();
|
||||||
|
List<LatLng> polylineCoordinates = [];
|
||||||
|
PolylinePoints polylinePoints;
|
||||||
|
|
||||||
|
Set<Marker> _markers = Set<Marker>();
|
||||||
|
|
||||||
|
BitmapDescriptor sourceIcon; // for my custom marker pins
|
||||||
|
BitmapDescriptor destinationIcon; // for my custom marker pins
|
||||||
|
Location location;// wrapper around the location API
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
_order = widget.order;
|
||||||
|
DEST_LOCATION = _order.shippingAddress.getLocation();
|
||||||
|
location = new Location();
|
||||||
|
polylinePoints = PolylinePoints();
|
||||||
|
setSourceAndDestinationIcons();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return new Scaffold(
|
||||||
|
body: GoogleMap(
|
||||||
|
myLocationEnabled: true,
|
||||||
|
compassEnabled: true,
|
||||||
|
markers: _markers,
|
||||||
|
polylines: _polylines,
|
||||||
|
mapType: MapType.normal,
|
||||||
|
initialCameraPosition: _orderDeliveryLocationCamera(),
|
||||||
|
onMapCreated: (GoogleMapController controller) {
|
||||||
|
_controller.complete(controller);
|
||||||
|
showPinsOnMap();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
floatingActionButton: FloatingActionButton.extended(
|
||||||
|
onPressed: _goToDriver,
|
||||||
|
label: Text('To the lake!'),
|
||||||
|
icon: Icon(Icons.directions_boat),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void setSourceAndDestinationIcons() async {
|
||||||
|
sourceIcon = await BitmapDescriptor.fromAssetImage(
|
||||||
|
ImageConfiguration(devicePixelRatio: 2.5),
|
||||||
|
'assets/images/map_markers/source_map_marker.png');
|
||||||
|
|
||||||
|
destinationIcon = await BitmapDescriptor.fromAssetImage(
|
||||||
|
ImageConfiguration(devicePixelRatio: 2.5),
|
||||||
|
'assets/images/map_markers/destination_map_marker.png');
|
||||||
|
}
|
||||||
|
|
||||||
|
CameraPosition _orderDeliveryLocationCamera(){
|
||||||
|
|
||||||
|
final CameraPosition orderDeliveryLocCamera = CameraPosition(
|
||||||
|
bearing: CAMERA_BEARING,
|
||||||
|
target: DEST_LOCATION,
|
||||||
|
tilt: CAMERA_TILT,
|
||||||
|
zoom: CAMERA_ZOOM);
|
||||||
|
return orderDeliveryLocCamera;
|
||||||
|
}
|
||||||
|
|
||||||
|
CameraPosition _driverLocationCamera(){
|
||||||
|
final CameraPosition driverLocCamera = CameraPosition(
|
||||||
|
bearing: CAMERA_BEARING,
|
||||||
|
target: SOURCE_LOCATION,
|
||||||
|
tilt: CAMERA_TILT,
|
||||||
|
zoom: CAMERA_ZOOM);
|
||||||
|
return driverLocCamera;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Future<void> _goToOrderDeliveryLocation() async {
|
||||||
|
final GoogleMapController controller = await _controller.future;
|
||||||
|
final CameraPosition orderDeliveryLocCamera = _orderDeliveryLocationCamera();
|
||||||
|
controller.animateCamera(CameraUpdate.newCameraPosition(orderDeliveryLocCamera));
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _goToDriver() async {
|
||||||
|
final GoogleMapController controller = await _controller.future;
|
||||||
|
final CameraPosition driverLocCamera = _driverLocationCamera();
|
||||||
|
controller.animateCamera(CameraUpdate.newCameraPosition(driverLocCamera));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Future<void> _fitCameraBetweenBothPoints() async {
|
||||||
|
final GoogleMapController controller = await _controller.future;
|
||||||
|
final CameraPosition driverLocCamera = CameraPosition(
|
||||||
|
bearing: CAMERA_BEARING,
|
||||||
|
target: SOURCE_LOCATION,
|
||||||
|
tilt: CAMERA_TILT,
|
||||||
|
zoom: CAMERA_ZOOM);
|
||||||
|
controller.animateCamera(CameraUpdate.newCameraPosition(driverLocCamera));
|
||||||
|
}
|
||||||
|
|
||||||
|
void showPinsOnMap() {
|
||||||
|
// source pin
|
||||||
|
if(SOURCE_LOCATION != null){
|
||||||
|
setState(() {
|
||||||
|
var pinPosition = SOURCE_LOCATION;
|
||||||
|
_markers.add(Marker(
|
||||||
|
markerId: MarkerId('sourcePin'),
|
||||||
|
position: pinPosition,
|
||||||
|
icon: sourceIcon
|
||||||
|
));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// destination pin
|
||||||
|
if(DEST_LOCATION != null){
|
||||||
|
setState(() {
|
||||||
|
var destPosition = DEST_LOCATION;
|
||||||
|
_markers.add(Marker(
|
||||||
|
markerId: MarkerId('destPin'),
|
||||||
|
position: destPosition,
|
||||||
|
icon: destinationIcon
|
||||||
|
));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// set the route lines on the map from source to destination
|
||||||
|
// for more info follow this tutorial
|
||||||
|
// drawRoute();
|
||||||
|
}
|
||||||
|
|
||||||
|
void updatePinOnMap() async {
|
||||||
|
// create a new CameraPosition instance
|
||||||
|
// every time the location changes, so the camera
|
||||||
|
// follows the pin as it moves with an animation
|
||||||
|
CameraPosition cPosition = CameraPosition(
|
||||||
|
zoom: CAMERA_ZOOM,
|
||||||
|
tilt: CAMERA_TILT,
|
||||||
|
bearing: CAMERA_BEARING,
|
||||||
|
target: SOURCE_LOCATION,
|
||||||
|
);
|
||||||
|
final GoogleMapController controller = await _controller.future;
|
||||||
|
controller.animateCamera(CameraUpdate.newCameraPosition(cPosition));
|
||||||
|
// do this inside the setState() so Flutter gets notified
|
||||||
|
// that a widget update is due
|
||||||
|
setState(() {
|
||||||
|
// updated position
|
||||||
|
var pinPosition = SOURCE_LOCATION;
|
||||||
|
|
||||||
|
// the trick is to remove the marker (by id)
|
||||||
|
// and add it again at the updated location
|
||||||
|
_markers.removeWhere((m) => m.markerId.value == 'sourcePin');
|
||||||
|
_markers.add(Marker(
|
||||||
|
markerId: MarkerId('sourcePin'),
|
||||||
|
position: pinPosition, // updated position
|
||||||
|
icon: sourceIcon
|
||||||
|
));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawRoute() async {
|
||||||
|
return; // Ignore draw Route
|
||||||
|
|
||||||
|
List<PointLatLng> result = await polylinePoints.getRouteBetweenCoordinates(
|
||||||
|
GOOGLE_API_KEY,
|
||||||
|
SOURCE_LOCATION.latitude,
|
||||||
|
SOURCE_LOCATION.longitude,
|
||||||
|
DEST_LOCATION.latitude,
|
||||||
|
DEST_LOCATION.longitude);
|
||||||
|
if(result.isNotEmpty){
|
||||||
|
result.forEach((PointLatLng point){
|
||||||
|
polylineCoordinates.add(
|
||||||
|
LatLng(point.latitude,point.longitude)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
setState(() {
|
||||||
|
_polylines.add(Polyline(
|
||||||
|
width: 5, // set the width of the polylines
|
||||||
|
polylineId: PolylineId('poly'),
|
||||||
|
color: Color.fromARGB(255, 40, 122, 198),
|
||||||
|
points: polylineCoordinates
|
||||||
|
));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue