google-maps - Flutter - 询问 Nearbyplaces 时出现错误
问题描述
嗨,我想在 Flutter 中实现谷歌地图和附近的搜索,我几乎做到了,但我不明白我在尝试获取我的位置附近的地方时遇到的错误。
我在网上搜索了,但我无法弄清楚,请谁能告诉我是什么问题。我花了将近 2 小时在网上搜索修复程序,但什么也没有。
这是代码:
import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:google_place/google_place.dart';
class MapScreen extends StatefulWidget {
@override
_MapScreenState createState() => _MapScreenState();
}
class _MapScreenState extends State<MapScreen> {
GoogleMapController mapController;
var googlePlace = GooglePlace("");
//this are the longitude and the latitude of the phone
double lng;
double lat;
void _onMapCreated(GoogleMapController controller) {
mapController = controller;
getPosition().then((value) => getLocationNearBy());
}
Future<Position> getPosition() async {
LocationPermission permission = await checkPermission();
LocationPermission permission2 = await requestPermission();
Position position =
await getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
lat = position.latitude;
lng = position.longitude;
print(position);
return position;
}
void getLocationNearBy() async {
var result = await googlePlace.search
.getNearBySearch(Location(lat: lat, lng: lng), 2000, type: "bars");
print(result);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: GoogleMap(
myLocationEnabled: true,
myLocationButtonEnabled: true,
onMapCreated: _onMapCreated,
initialCameraPosition: CameraPosition(
target: _center,
zoom: 11.0,
),
),
),
);
}
}
这是错误:
Considering local module com.google.android.gms.googlecertificates:0 and remote module
com.google.android.gms.googlecertificates:6
I/DynamiteModule(18683): Selected remote version of com.google.android.gms.googlecertificates, version >= 6
I/DynamiteLoaderV2Impl(18683): [71] Googlecertificates
W/m.example.ipil(18683): ClassLoaderContext type mismatch. expected=PCL, found=DLC (PCL[] | DLC[];PCL[/data/app/com.example.ipill-sEbMOSkwYUXtrKfO0SfLPQ==/base.apk*4144957280:/data/app/com.example.ipill-sEbMOSkwYUXtrKfO0SfLPQ==/base.apk!classes2.dex*3286414090:/data/app/com.example.ipill-sEbMOSkwYUXtrKfO0SfLPQ==/base.apk!classes3.dex*660981783:/data/app/com.example.ipill-sEbMOSkwYUXtrKfO0SfLPQ==/base.apk!classes4.dex*371746816:/data/app/com.example.ipill-sEbMOSkwYUXtrKfO0SfLPQ==/base.apk!classes5.dex*1029310577:/data/app/com.example.ipill-sEbMOSkwYUXtrKfO0SfLPQ==/base.apk!classes6.dex*1730292004:/data/app/com.example.ipill-sEbMOSkwYUXtrKfO0SfLPQ==/base.apk!classes7.dex*2560797352:/data/app/com.example.ipill-sEbMOSkwYUXtrKfO0SfLPQ==/base.apk!classes8.dex*1790620740:/data/app/com.example.ipill-sEbMOSkwYUXtrKfO0SfLPQ==/base.apk!classes9.dex*2957673897:/data/app/com.example.ipill-sEbMOSkwYUXtrKfO0SfLPQ==/base.apk!classes10.dex*1136895787:/data/app/com.example.ipill-sEbMOSkwYUXtrKfO0SfLPQ==/base.apk!classes11.dex*1461101890:/data/app/com
W/m.example.ipil(18683): Found duplicate classes, falling back to extracting from APK : /data/user_de/0/com.google.android.gms/app_chimera/m/000000d4/GoogleCertificates.apk
W/m.example.ipil(18683): NOTE: This wastes RAM and hurts startup performance.
W/m.example.ipil(18683): Found duplicated class when checking oat files: 'Landroidx/annotation/Keep;' in /data/user_de/0/com.google.android.gms/app_chimera/m/000000d4/GoogleCertificates.apk and /data/app/com.example.ipill-sEbMOSkwYUXtrKfO0SfLPQ==/base.apk!classes13.dex
W/m.example.ipil(18683):
W/m.example.ipil(18683): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
I/m.example.ipil(18683): NativeAlloc concurrent copying GC freed 83801(6328KB) AllocSpace objects, 143(8420KB) LOS objects, 49% free, 7253KB/14MB, paused 211us total 141.179ms
W/m.example.ipil(18683): Accessing hidden method Lsun/misc/Unsafe;->putObject(Ljava/lang/Object;JLjava/lang/Object;)V (greylist, linking, allowed)
W/m.example.ipil(18683): Accessing hidden method Lsun/misc/Unsafe;->putLong(Ljava/lang/Object;JJ)V (greylist, linking, allowed)
W/m.example.ipil(18683): Accessing hidden method Lsun/misc/Unsafe;->getInt(Ljava/lang/Object;J)I (greylist, linking, allowed)
W/m.example.ipil(18683): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
I/chatty (18683): uid=10378(com.example.ipill) GoogleApiHandle identical 3 lines
W/m.example.ipil(18683): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
W/m.example.ipil(18683): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
W/m.example.ipil(18683): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
W/m.example.ipil(18683): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
I/chatty (18683): uid=10378(com.example.ipill) GoogleApiHandle identical 2 lines
W/m.example.ipil(18683): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
W/m.example.ipil(18683): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
W/m.example.ipil(18683): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
W/m.example.ipil(18683): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
W/m.example.ipil(18683): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
I/chatty (18683): uid=10378(com.example.ipill) GoogleApiHandle identical 1 line
W/m.example.ipil(18683): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
W/m.example.ipil(18683): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
I/chatty (18683): uid=10378(com.example.ipill) GoogleApiHandle identical 5 lines
W/m.example.ipil(18683): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
W/m.example.ipil(18683): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
W/m.example.ipil(18683): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
W/m.example.ipil(18683): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
I/chatty (18683): uid=10378(com.example.ipill) GoogleApiHandle identical 4 lines
解决方案
要解决此问题,请确保您的 pubspec.yaml 和 google.services.gms 中没有包位置。
推荐阅读
- python - 为什么'datetime.date'对象没有属性'__dict__'?
- c++ - 显示抛出 std::out_of_range 实例的错误
- java - 如何在存储在列表中的多个分隔符上拆分字符串?
- javascript - 如何使用 javascript 打开和关闭折叠
- asp.net-core-mvc - 在操作方法 ASP.Net MVC Core 之间传递复杂对象
- javascript - 如何仅在桌面设备上呈现 DIV 标签(宽度 > 1024)
- graphql - Hasura:如何在插入时建立与现有记录(多对多)的关系?
- selenium - 如何使用机器人框架脚本进行负载测试或性能测试
- javascript - 我想在我的登录页面添加一个忘记密码的页面,但我更新代码后无法跳转
- airflow - 如何使用气流安排任务