Flutter- Getting and error when asking for Nearbyplaces

≡放荡痞女 提交于 2021-02-11 17:52:50

问题


Hi I want to implement Google Map and nearby Search in Flutter and I almost did it but I don't understand the error that I'm getting while trying to fetch the places near my position.

I searched online but I couldn't figure it out, can anyone tell me what is wrong please. I lost almost 2h searching the web for the fix but nothing.

This is the code :

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,
          ),
        ),
      ),
    );
  }
}

This is the error:

 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

回答1:


To solve this problem make sure you don't have the package location in your pubspec.yaml and at the same time, google.services.gms.



来源:https://stackoverflow.com/questions/63961843/flutter-getting-and-error-when-asking-for-nearbyplaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!