# flutter_geolocator_cn
**Repository Path**: weebo/flutter_geolocator_cn
## Basic Information
- **Project Name**: flutter_geolocator_cn
- **Description**: flutter 国内可用的免费的系统定位
高德地图、百度地图不再免费。而flutter的定位 插件 geolocator 需要安装谷歌服务或者谷歌商店 才可以定位,所以修改了源码写了个demo,参照*Super-Bin大神的文章:https://blog.csdn.net/ZZB_Bin/article/details/121553574?utm_source=miniapp_weixin*
- **Primary Language**: Dart
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 2
- **Created**: 2024-09-23
- **Last Updated**: 2024-09-23
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# 国内可用的免费的系统定位
### 高德地图、百度地图不再免费。而flutter的定位 插件 geolocator 需要安装谷歌服务或者谷歌商店 才可以定位,所以修改了源码写了个demo,参照*Super-Bin大神的文章:https://blog.csdn.net/ZZB_Bin/article/details/121553574?utm_source=miniapp_weixin*
注:本demo 是源码,不是直接引入库
- 食用:
- 在 项目=>android=>app=>src=>main 下面的 AndroidManifest.xml 中加入Android 权限
```
```
- 在 项目=>ios=>Runner=>Info.plist 中加入IOS权限
```
NSLocationWhenInUseUsageDescription
This app needs access to location when open.
NSLocationAlwaysUsageDescription
This app needs access to location when in the background.
```
- 在项目 目录下新建一个文件夹plugin(像当前的demo一样,可以整个plugin文件夹复制过去)
- 把这个工程中的plugin文件夹下的geolocator-7.0.0、geolocator_platform_interface-2.3.6、plugin_platform_interface-2.1.6 拷贝进你的plugin文件夹下
- 用法
```
Position position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
print(position);
```
## 如果需要详细的地址,可以根据经纬度,请求天地图的详细address,可以获得详细地址:例如北京市东城区城隍庙东20米男厕:
是这个接口:
```
http://api.tianditu.gov.cn/geocoder?postStr={'lon':" + 经度 + ",'lat':" + 纬度 + ",'ver':1}&type=geocode&tk=自己在官网申请的key
```
# 点个赞吧,不花钱的!
------
### 以下是 一些不重要的,可以不看!
- 当前的geolocator版本是7.0.0
- 默认使用android系统定位,如果不适用系统定位,会默认使用google新的定位,那么就需要安装谷歌服务或者谷歌商店。
- 改过了源码,优先使用gps定位,如果gps定位取不到,那么使用网络定位。
- 网络定位的范围改大
- 用法
```
void _getPosition() async{
Position position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high,forceAndroidLocationManager: true);
print(position);
}
```
或者(不使用async/await 组合)
```
void _getPosition(){
Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high,forceAndroidLocationManager: true).then((positon){
print(positon);
});
}
```