google-maps - Flutter-请求附近地点时出现错误

标签 google-maps flutter google-nearby

您好,我想在 Flutter 中实现 Google map 和附近的搜索,我几乎做到了,但我不明白在尝试获取我的位置附近的地点时遇到的错误。

网上查了也没明白,请问谁能告诉我哪里出了问题吗?我花了近 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 中也没有该软件包位置。

关于google-maps - Flutter-请求附近地点时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63961843/

相关文章:

javascript - 在谷歌地图 react 的标记上添加工具提示

android - flutter 插件 : Send data from Android BroadcastReceiver to Flutter code

android - 我如何在不同方向上创建两个彼此滚动的可滚动列表

android - 附近的 Google Play 服务注册失败,有 TOO_MANY_PENDING_INTENTS 个

android - 如何在多个 Activity 中使用 Android Nearby Connections

android - 是否可以从手机设置中授予 Nearby API 权限?

ios - 谷歌自动完成教程 places api for swift

java - Android 位置权限代码无法正常工作

javascript - Google map - jQuery - Php 集成检查

带图标的 Flutter 数字文本字段