{"id":18836804,"url":"https://github.com/loup-v/geolocation","last_synced_at":"2025-04-06T01:08:09.337Z","repository":{"id":49594239,"uuid":"127793344","full_name":"loup-v/geolocation","owner":"loup-v","description":"Flutter geolocation plugin for Android and iOS.","archived":false,"fork":false,"pushed_at":"2022-07-22T10:34:01.000Z","size":567,"stargazers_count":227,"open_issues_count":24,"forks_count":94,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-03-30T00:06:53.509Z","etag":null,"topics":["flutter","flutter-plugin","geocoder","geolocation","gps","location"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/loup-v.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-02T18:05:30.000Z","updated_at":"2025-03-24T08:40:20.000Z","dependencies_parsed_at":"2022-09-06T08:11:26.837Z","dependency_job_id":null,"html_url":"https://github.com/loup-v/geolocation","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loup-v%2Fgeolocation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loup-v%2Fgeolocation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loup-v%2Fgeolocation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loup-v%2Fgeolocation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loup-v","download_url":"https://codeload.github.com/loup-v/geolocation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247419860,"owners_count":20936012,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["flutter","flutter-plugin","geocoder","geolocation","gps","location"],"created_at":"2024-11-08T02:32:08.405Z","updated_at":"2025-04-06T01:08:09.320Z","avatar_url":"https://github.com/loup-v.png","language":"Dart","readme":"# geolocation\n\n[![pub package](https://img.shields.io/pub/v/geolocation.svg)](https://pub.dartlang.org/packages/geolocation)\n\nFlutter [geolocation plugin](https://pub.dartlang.org/packages/geolocation/) for Android API 16+ and iOS 9+.\n\nFeatures:\n\n- Manual and automatic location permission management\n- Current one-shot location\n- Continuous location updates with foreground and background options\n\nThe plugin is under active development and the following features are planned soon:\n\n- Geocode\n- Geofences\n- Place suggestions\n- Activity recognition\n- Exposition of iOS/Android specific APIs (like significant location updates on iOS)\n\n|                                          Android                                           |                                          iOS                                           |\n| :----------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------: |\n| ![](https://github.com/loup-v/geolocation/blob/master/doc/android_screenshot.jpg?raw=true) | ![](https://github.com/loup-v/geolocation/blob/master/doc/ios_screenshot.jpg?raw=true) |\n\n### Installation\n\nFollow the instructions: https://pub.dev/packages/geolocation#-installing-tab-\n\n#### iOS\n\n##### Objective-C compatibility\n\nFor Flutter projects created with the Objective-C template, you might need to add `use_frameworks!` at the top of `ios/Podfile`.\nMore details can be found in the following issue: https://github.com/flutter/flutter/issues/16049#issuecomment-552060349\n\n#### Android\n\n##### AndroidX\n\nGeolocation is dependent on AndroidX. Make sure to include the following settings to 'android/gradle.properties':\n\n```\nandroid.useAndroidX=true\nandroid.enableJetifier=true\n```\n\n##### R8/Proguard code obfuscation\n\nIf you have enabled code obfuscation with R8 or proguard, you need to add the following rules.\n\n`android/app/build.gradle`:\n\n```groovy\nbuildTypes {\n  release {\n    minifyEnabled true\n    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'\n  }\n}\n```\n\n`android/app/proguard-rules.pro`:\n\n```\n# Geolocation - start\n\n-keep class app.loup.geolocation.** { *; }\n\n    # Moshi - start\n    # https://github.com/square/moshi/blob/master/moshi/src/main/resources/META-INF/proguard/moshi.pro\n\n    # JSR 305 annotations are for embedding nullability information.\n    -dontwarn javax.annotation.**\n\n    -keepclasseswithmembers class * {\n        @com.squareup.moshi.* \u003cmethods\u003e;\n    }\n\n    -keep @com.squareup.moshi.JsonQualifier interface *\n\n    # Enum field names are used by the integrated EnumJsonAdapter.\n    # values() is synthesized by the Kotlin compiler and is used by EnumJsonAdapter indirectly\n    # Annotate enums with @JsonClass(generateAdapter = false) to use them with Moshi.\n    -keepclassmembers @com.squareup.moshi.JsonClass class * extends java.lang.Enum {\n        \u003cfields\u003e;\n        **[] values();\n    }\n\n    # Moshi - end\n\n# Geolocation - end\n```\n\n### Permission\n\nAndroid and iOS require to declare the location permission in a configuration file.\n\n#### For iOS\n\nThere are two kinds of location permission available in iOS: \"when in use\" and \"always\".\n\nIf you don't know what permission to choose for your usage, see:\nhttps://developer.apple.com/documentation/corelocation/choosing_the_authorization_level_for_location_services\n\nYou need to declare the description for the desired permission in `ios/Runner/Info.plist`:\n\n```xml\n\u003cdict\u003e\n  \u003c!-- for iOS 11 + --\u003e\n  \u003ckey\u003eNSLocationWhenInUseUsageDescription\u003c/key\u003e\n  \u003cstring\u003eReason why app needs location\u003c/string\u003e\n  \u003ckey\u003eNSLocationAlwaysAndWhenInUseUsageDescription\u003c/key\u003e\n  \u003cstring\u003eReason why app needs location\u003c/string\u003e\n\n  \u003c!-- additionally for iOS 9/10, if you need always permission --\u003e\n  \u003ckey\u003eNSLocationAlwaysUsageDescription\u003c/key\u003e\n  \u003cstring\u003eReason why app needs location\u003c/string\u003e\n  ...\n\u003c/dict\u003e\n```\n\n#### For Android\n\nThere are two kinds of location permission in Android: \"coarse\" and \"fine\".\nCoarse location will allow to get approximate location based on sensors like the Wifi, while fine location returns the most accurate location using GPS (in addition to coarse).\n\nYou need to declare one of the two permissions in `android/app/src/main/AndroidManifest.xml`:\n\n```xml\n\u003cmanifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\u003e\n  \u003cuses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\" /\u003e\n  \u003c!-- or --\u003e\n  \u003cuses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\" /\u003e\n\u003c/manifest\u003e\n```\n\nNote that `ACCESS_FINE_LOCATION` permission includes `ACCESS_COARSE_LOCATION`.\n\n## API\n\nFor more complete documentation on all usage, check the API documentation:  \nhttps://pub.dartlang.org/documentation/geolocation/latest/geolocation/geolocation-library.html\n\nYou can also check the example project that showcase a comprehensive usage of Geolocation plugin.\n\n### Check if location service is operational\n\nAPI documentation: https://pub.dartlang.org/documentation/geolocation/latest/geolocation/Geolocation/isLocationOperational.html\n\n```dart\nfinal GeolocationResult result = await Geolocation.isLocationOperational();\nif(result.isSuccessful) {\n  // location service is enabled, and location permission is granted\n} else {\n  // location service is not enabled, restricted, or location permission is denied\n}\n```\n\n### Request location permission\n\nOn Android (api 23+) and iOS, apps need to request location permission at runtime.\n\n_Note: You are not required to request permission manually.\nGeolocation plugin will request permission automatically if it's needed, when you make a location request._\n\nAPI documentation: https://pub.dartlang.org/documentation/geolocation/latest/geolocation/Geolocation/requestLocationPermission.html\n\n```dart\nfinal GeolocationResult result = await Geolocation.requestLocationPermission(\n  const LocationPermission(\n    android: LocationPermissionAndroid.fine,\n    ios: LocationPermissionIOS.always,\n  ),\n  openSettingsIfDenied: true,\n);\n\nif(result.isSuccessful) {\n  // location permission is granted (or was already granted before making the request)\n} else {\n  // location permission is not granted\n  // user might have denied, but it's also possible that location service is not enabled, restricted, and user never saw the permission request dialog. Check the result.error.type for details.\n}\n```\n\n### Get the current one-shot location\n\nGeolocation offers three methods:\n\n- Last known location (best on Android):  \n  https://pub.dartlang.org/documentation/geolocation/latest/geolocation/Geolocation/lastKnownLocation.html\n- Single location update (best on iOS):  \n  https://pub.dartlang.org/documentation/geolocation/latest/geolocation/Geolocation/singleLocationUpdate.html\n- Current location (best of both worlds, tries to retrieve last known location on Android, otherwise requests a single location update):  \n  https://pub.dartlang.org/documentation/geolocation/latest/geolocation/Geolocation/currentLocation.html\n\n```dart\n// get last known location, which is a future rather than a stream (best for android)\nLocationResult result = await Geolocation.lastKnownLocation();\n\n// force a single location update (best for ios)\nStreamSubscription\u003cLocationResult\u003e subscription = Geolocation.currentLocation(accuracy: LocationAccuracy.best).listen((result) {\n  // todo with result\n});\n\n// best option for most cases\nStreamSubscription\u003cLocationResult\u003e subscription = Geolocation.currentLocation(accuracy: LocationAccuracy.best).listen((result) {\n  if(result.isSuccessful) {\n    Double latitude = result.location.latitude;\n    // todo with result\n  }\n});\n```\n\n### Continuous location updates\n\nAPI documentation: https://pub.dartlang.org/documentation/geolocation/latest/geolocation/Geolocation/locationUpdates.html\n\n```dart\nStreamSubscription\u003cLocationResult\u003e subscription = Geolocation.locationUpdates(\n    accuracy: LocationAccuracy.best,\n    displacementFilter: 10.0, // in meters\n    inBackground: true, // by default, location updates will pause when app is inactive (in background). Set to `true` to continue updates in background.\n  )\n  .listen((result) {\n    if(result.isSuccessful) {\n      // todo with result\n    }\n  });\n\n\n// cancelling subscription will also stop the ongoing location request\nsubscription.cancel();\n```\n\n### Handle location result\n\nLocation request return either a `LocationResult` future or a stream of `LocationResult`.\n\nAPI documentation: https://pub.dartlang.org/documentation/geolocation/latest/geolocation/LocationResult-class.html\n\n```dart\nLocationResult result = await Geolocation.lastKnownLocation();\n\nif (result.isSuccessful) {\n  // location request successful, location is guaranteed to not be null\n  double lat = result.location.latitude;\n  double lng = result.location.longitude;\n} else {\n  switch (result.error.type) {\n    case GeolocationResultErrorType.runtime:\n      // runtime error, check result.error.message\n      break;\n    case GeolocationResultErrorType.locationNotFound:\n      // location request did not return any result\n      break;\n    case GeolocationResultErrorType.serviceDisabled:\n      // location services disabled on device\n      // might be that GPS is turned off, or parental control (android)\n      break;\n    case GeolocationResultErrorType.permissionNotGranted:\n      // location has not been requested yet\n      // app must request permission in order to access the location\n      break;\n    case GeolocationResultErrorType.permissionDenied:\n      // user denied the location permission for the app\n      // rejection is final on iOS, and can be on Android if user checks `don't ask again`\n      // user will need to manually allow the app from the settings, see requestLocationPermission(openSettingsIfDenied: true)\n      break;\n    case GeolocationResultErrorType.playServicesUnavailable:\n      // android only\n      // result.error.additionalInfo contains more details on the play services error\n      switch(result.error.additionalInfo as GeolocationAndroidPlayServices) {\n        // do something, like showing a dialog inviting the user to install/update play services\n        case GeolocationAndroidPlayServices.missing:\n        case GeolocationAndroidPlayServices.updating:\n        case GeolocationAndroidPlayServices.versionUpdateRequired:\n        case GeolocationAndroidPlayServices.disabled:\n        case GeolocationAndroidPlayServices.invalid:\n      }\n    break;\n  }\n}\n```\n\n## Authors\n\nGeolocation plugin is developed by Loup, a mobile development studio based in Montreal and Paris.  \nYou can contact us at \u003chello@loup.app\u003e\n\n## Contributers\n\n- lukaspili\n- mit-mit\n- shehabic-work\n- Abgaryan\n- shehabic\n- alfanhui\n\n## License\n\nApache License 2.0\n","funding_links":[],"categories":["插件","Device [🔝](#readme)","Plugins"],"sub_categories":["设备","Device","Monetization"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floup-v%2Fgeolocation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floup-v%2Fgeolocation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floup-v%2Fgeolocation/lists"}