Flutter emulator上的应用程序运行完美,但在真实设备上运行时,位置标记不可见,并且在运行代码时显示无法加载资源
因为问题是emulator中的一切工作正常……即使资源在emulator中成功加载,堆栈仍显示无法加载资源,而且在emulator上成功测试应用程序后,当我在真实设备上运行应用程序时,位置标记不可见,而在emulator中可见Flutter emulator上的应用程序运行完美,但在真实设备上运行时,位置标记不可见,并且在运行代码时显示无法加载资源,flutter,geolocation,android-emulator,google-maps-markers,assets,Flutter,Geolocation,Android Emulator,Google Maps Markers,Assets,因为问题是emulator中的一切工作正常……即使资源在emulator中成功加载,堆栈仍显示无法加载资源,而且在emulator上成功测试应用程序后,当我在真实设备上运行应用程序时,位置标记不可见,而在emulator中可见 //This is my code import 'package:flutter_polyline_points/flutter_polyline_points.dart'; import 'package:google_maps_flutter/googl
//This is my code
import 'package:flutter_polyline_points/flutter_polyline_points.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:location/location.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'components/map_pin_pill.dart';
import 'Model/pin_pill_info.dart';
const double CAMERA_ZOOM = 16;
const double CAMERA_TILT = 80;
const double CAMERA_BEARING = 30;
const LatLng SOURCE_LOCATION = LatLng(28.357932, 77.167889);
const LatLng DEST_LOCATION = LatLng(28.354017, 77.1605916);
void main() =>
runApp(MaterialApp(debugShowCheckedModeBanner: false, home: MapPage()));
class MapPage extends StatefulWidget {
@override
State<StatefulWidget> createState() => MapPageState();
}
class MapPageState extends State<MapPage> {
Completer<GoogleMapController> _controller = Completer();
Set<Marker> _markers = Set<Marker>();
// for my drawn routes on the map
Set<Polyline> _polylines = Set<Polyline>();
List<LatLng> polylineCoordinates = [];
PolylinePoints polylinePoints= PolylinePoints();
String googleAPIKey = '';
// for my custom marker pins
BitmapDescriptor sourceIcon;
BitmapDescriptor destinationIcon;
// the user's initial location and current location
// as it moves
LocationData currentLocation;
// a reference to the destination location
LocationData destinationLocation;
// wrapper around the location API
Location location;
double pinPillPosition = -100;
PinInformation currentlySelectedPin = PinInformation(
pinPath: '',
avatarPath: '',
location: LatLng(0, 0),
locationName: '',
labelColor: Colors.grey);
PinInformation sourcePinInfo;
PinInformation destinationPinInfo;
@override
void initState() {
super.initState();
// create an instance of Location
location = new Location();
polylinePoints = PolylinePoints();
// subscribe to changes in the user's location
// by "listening" to the location's onLocationChanged event
location.onLocationChanged.listen((LocationData cLoc) {
// cLoc contains the lat and long of the
// current user's position in real time,
// so we're holding on to it
currentLocation = cLoc;
updatePinOnMap();
});
// set custom marker pins
setSourceAndDestinationIcons();
// set the initial location
setInitialLocation();
}
void setSourceAndDestinationIcons() async {
BitmapDescriptor.fromAssetImage(
ImageConfiguration(devicePixelRatio: 2.0), 'assets/driving_pin.png')
.then((onValue) {
sourceIcon = onValue;
});
BitmapDescriptor.fromAssetImage(ImageConfiguration(devicePixelRatio: 2.0),
'assets/destination_map_marker.png')
.then((onValue) {
destinationIcon = onValue;
});
}
void setInitialLocation() async {
// set the initial location by pulling the user's
// current location from the location's getLocation()
currentLocation = await location.getLocation();
// hard-coded destination for this example
destinationLocation = LocationData.fromMap({
"latitude": DEST_LOCATION.latitude,
"longitude": DEST_LOCATION.longitude
});
}
@override
Widget build(BuildContext context) {
CameraPosition initialCameraPosition = CameraPosition(
zoom: CAMERA_ZOOM,
tilt: CAMERA_TILT,
bearing: CAMERA_BEARING,
target: SOURCE_LOCATION);
if (currentLocation != null) {
initialCameraPosition = CameraPosition(
target: LatLng(currentLocation.latitude, currentLocation.longitude),
zoom: CAMERA_ZOOM,
tilt: CAMERA_TILT,
bearing: CAMERA_BEARING);
}
return Scaffold(
body: Stack(
children: <Widget>[
GoogleMap(
myLocationEnabled: true,
compassEnabled: true,
tiltGesturesEnabled: false,
markers: _markers,
polylines: _polylines,
mapType: MapType.normal,
initialCameraPosition: initialCameraPosition,
onTap: (LatLng loc) {
pinPillPosition = -100;
},
onMapCreated: (GoogleMapController controller) {//dikkat
// controller.setMapStyle(Utils.mapStyles);
_controller.complete(controller);
// my map has completed being created;
// i'm ready to show the pins on the map
showPinsOnMap();
}),
MapPinPillComponent(
pinPillPosition: pinPillPosition,
currentlySelectedPin: currentlySelectedPin),
Positioned(
bottom: 90,
right: 10,
child:
FlatButton(
child: Icon(Icons.pin_drop, color: Colors.white),
color: Colors.green,
onPressed: updatePinOnMap
)
),
],
),
);
}
void showPinsOnMap() {
// get a LatLng for the source location
// from the LocationData currentLocation object
var pinPosition =
LatLng(currentLocation.latitude, currentLocation.longitude);
// get a LatLng out of the LocationData object
var destPosition =
LatLng(destinationLocation.latitude, destinationLocation.longitude);
sourcePinInfo = PinInformation(
locationName: "Start Location",
location: SOURCE_LOCATION,
pinPath: "assets/driving_pin.png",
avatarPath: "assets/friend1.jpg",
labelColor: Colors.blueAccent);
destinationPinInfo = PinInformation(
locationName: "End Location",
location: DEST_LOCATION,
pinPath: "assets/destination_map_marker.png",
avatarPath: "assets/friend2.jpg",
labelColor: Colors.purple);
// add the initial source location pin
_markers.add(Marker(
markerId: MarkerId('sourcePin'),
position: pinPosition,
onTap: () {
setState(() {
currentlySelectedPin = sourcePinInfo;
pinPillPosition = 0;
});
},
icon: sourceIcon));
// destination pin
_markers.add(Marker(
markerId: MarkerId('destPin'),
position: destPosition,
onTap: () {
setState(() {
currentlySelectedPin = destinationPinInfo;
pinPillPosition = 0;
});
},
icon: destinationIcon));
// set the route lines on the map from source to destination
// for more info follow this tutorial
setPolylines();
}
void setPolylines() async {
PolylineResult result = await polylinePoints.getRouteBetweenCoordinates(googleAPIKey,
PointLatLng(currentLocation.latitude, currentLocation.longitude),
PointLatLng(destinationLocation.latitude,destinationLocation.longitude));
if(result.points.isNotEmpty) {
print("not empty");
result.points.forEach((PointLatLng point) {
polylineCoordinates.add(LatLng(point.latitude, point.longitude));
});
setState(() {
_polylines.add(Polyline(
width: 3, // set the width of the polylines
polylineId: PolylineId("poly"),
color: Color.fromARGB(255, 40, 122, 198),
points: polylineCoordinates));
});
}
}
void updatePinOnMap() async {
// create a new CameraPosition instance
// every time the location changes, so the camera
// follows the pin as it moves with an animation
CameraPosition cPosition = CameraPosition(
zoom: CAMERA_ZOOM,
tilt: CAMERA_TILT,
bearing: CAMERA_BEARING,
target: LatLng(currentLocation.latitude, currentLocation.longitude),
);
final GoogleMapController controller = await _controller.future;
controller.animateCamera(CameraUpdate.newCameraPosition(cPosition));
// do this inside the setState() so Flutter gets notified
// that a widget update is due
setState(() {
// updated position
var pinPosition =
LatLng(currentLocation.latitude, currentLocation.longitude);
sourcePinInfo.location = pinPosition;
// the trick is to remove the marker (by id)
// and add it again at the updated location
_markers.removeWhere((m) => m.markerId.value == 'sourcePin');
_markers.add(Marker(
markerId: MarkerId('sourcePin'),
onTap: () {
setState(() {
currentlySelectedPin = sourcePinInfo;
pinPillPosition = 0;
});
},
position: pinPosition, // updated position
icon: sourceIcon));
});
}
}
//这是我的代码
导入“包:颤振多段线点/颤振多段线点.省道”;
导入“包:google_-maps_-flatter/google_-maps_-flatter.dart”;
导入“package:location/location.dart”;
进口“包装:颤振/材料.省道”;
导入“dart:async”;
导入“组件/map_pin_pill.dart”;
导入'Model/pin_pill_info.dart';
const双摄像机_变焦=16;
const双摄像头倾斜=80;
常数双摄像机_轴承=30;
const LatLng SOURCE_LOCATION=LatLng(28.357932,77.167889);
const-LatLng DEST_位置=LatLng(28.354017,77.1605916);
void main()=>
runApp(MaterialApp(debugShowCheckedModeBanner:false,home:MapPage());
类MapPage扩展StatefulWidget{
@凌驾
State createState()=>MapPageState();
}
类MapPageState扩展了状态{
Completer _controller=Completer();
Set _markers=Set();
//我在地图上画的路线
Set _polylines=Set();
列出多段线坐标=[];
多段线点多段线点=多段线点();
字符串googleAPIKey='';
//为我的自定义标记别针
位图描述符源图标;
位映射描述符定义;
//用户的初始位置和当前位置
//当它移动时
位置数据当前位置;
//对目标位置的引用
位置数据目的地位置;
//位置API的包装器
位置;
双针孔位置=-100;
PinInformation currentlySelectedPin=PinInformation(
pinPath:“”,
化身路径:“”,
位置:LatLng(0,0),
位置名称:“”,
标签颜色:颜色。灰色);
pininfo信息源pininfo;
PinInformation destinationPinInfo;
@凌驾
void initState(){
super.initState();
//创建位置的实例
位置=新位置();
多段线点=多段线点();
//订阅用户位置的更改
//通过“侦听”位置的onLocationChanged事件
location.onLocationChanged.listen((LocationData cLoc){
//cLoc包含对象的lat和long
//实时显示当前用户的位置,
//所以我们坚持住了
currentLocation=cLoc;
updateMap();
});
//设置自定义标记销
设置来源和目的();
//设置初始位置
setInitialLocation();
}
void setSourceAndDestinations()异步{
BitmapDescriptor.fromAssetImage(
ImageConfiguration(devicePixelRatio:2.0),“资产/驱动_pin.png”)
.然后((onValue){
sourceIcon=onValue;
});
BitmapDescriptor.fromAssetImage(图像配置(devicePixelRatio:2.0),
“assets/destination\u map\u marker.png”)
.然后((onValue){
目的地=价值;
});
}
void setInitialLocation()异步{
//通过拉动用户的鼠标来设置初始位置
//来自位置的getLocation()的当前位置
currentLocation=等待位置。getLocation();
//本例中的硬编码目的地
destinationLocation=LocationData.fromMap({
“纬度”:目的地位置。纬度,
“经度”:DEST_LOCATION.longitude
});
}
@凌驾
小部件构建(构建上下文){
CameraPosition initialCameraPosition=CameraPosition(
变焦:相机变焦,
倾斜:摄像机倾斜,
轴承:摄像机轴承,
目标:源位置);
if(currentLocation!=null){
initialCameraPosition=CameraPosition(
目标:LatLng(currentLocation.latitude,currentLocation.longitude),
变焦:相机变焦,
倾斜:摄像机倾斜,
轴承:摄像机轴承);
}
返回脚手架(
主体:堆栈(
儿童:[
谷歌地图(
myLocationEnabled:对,
同谋:是的,
tiltGesturesEnabled:false,
标记:_标记,
多段线:_多段线,
mapType:mapType.normal,
initialCameraPosition:initialCameraPosition,
onTap:(LatLng loc){
pinPillPosition=-100;
},
onMapCreated:(谷歌地图控制器){//dikkat
//controller.setMapStyle(Utils.mapStyles);
_控制器。完成(控制器);
//我的地图已经完成创建;
//我已经准备好在地图上显示图钉了
showPinsOnMap();
}),
MapPinpill组件(
pinPillPosition:pinPillPosition,
currentlySelectedPin:currentlySelectedPin),
定位(
底部:90,
右:10,,
儿童:
扁平按钮(
子:图标(Icons.pin_drop,颜色:Colors.white),
颜色:颜色。绿色,
onPressed:UpdateMap
)
),
],
),
);
}
void showPinsOnMap(){
//获取源位置的LatLng
//从LocationData currentLocation对象
var精确定位=
LatLng(当前位置.纬度,当前位置.经度);
//从LocationData对象中获取一个LatLng
无功位移=
LatLng(目的地位置.纬度,目的地位置.经度);
sourcePinInfo=PinInformation(
locationName:“开始位置”,
位置:源位置,
pinPath:“资产/driving_pin.png”,
头像路径:“资产/友谊1.jpg”,
标签颜色:颜色。蓝色调);
destinationPinInfo=PinInformation(
locationName:“结束位置”,
Syncing files to device Android SDK built for x86...
D/EGL_emulation( 9741): eglMakeCurrent: 0xa6584ea0: ver 2 0 (tinfo 0x90713ec0)
E/BufferQueueProducer( 9741): [SurfaceTexture-0-9741-1] setAsyncMode: BufferQueue has been abandoned
E/BufferQueueProducer( 9741): [SurfaceTexture-0-9741-1] cancelBuffer: BufferQueue has been abandoned
Restarted application in 3,158ms.
W/DynamiteModule( 9741): Local module descriptor class for providerinstaller not found.
I/DynamiteModule( 9741): Considering local module providerinstaller:0 and remote module providerinstaller:0
W/ProviderInstaller( 9741): Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
W/ConnectivityManager.CallbackHandler( 9741): callback not found for CALLBACK_CAP_CHANGED message
W/ConnectivityManager.CallbackHandler( 9741): callback not found for CALLBACK_IP_CHANGED message
W/DynamiteModule( 9741): Local module descriptor class for providerinstaller not found.
I/DynamiteModule( 9741): Considering local module providerinstaller:0 and remote module providerinstaller:0
W/ProviderInstaller( 9741): Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
W/ConnectivityManager.CallbackHandler( 9741): callback not found for CALLBACK_IP_CHANGED message
I/Google Maps Android API( 9741): Google Play services package version: 203019022
D/ ( 9741): HostConnection::get() New Host Connection established 0x872a9500, tid 10180
D/EGL_emulation( 9741): eglCreateContext: 0x8f55fda0: maj 1 min 0 rcv 1
D/EGL_emulation( 9741): eglMakeCurrent: 0xa6584ea0: ver 2 0 (tinfo 0x90713ec0)
I/flutter ( 9741): GOOGLE MAPS URL: https://maps.googleapis.com/maps/api/directions/json?origin=28.3524217%2C77.3368383&destination=28.354017%2C77.16059159999998&mode=driving&avoidHighways=false&avoidFerries=true&avoidTolls=false&key=API_KEY
D/EGL_emulation( 9741): eglMakeCurrent: 0x8f55fda0: ver 1 0 (tinfo 0x8f4360f0)
══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
The following assertion was thrown resolving an image codec:
Unable to load asset:
When the exception was thrown, this was the stack:
#0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:223:7)
<asynchronous suspension>
#1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:669:31)
#2 AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:652:14)
#3 ImageProvider.resolveStreamForKey.<anonymous closure> (package:flutter/src/painting/image_provider.dart:505:13)
#4 ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:360:22)
#5 ImageProvider.resolveStreamForKey (package:flutter/src/painting/image_provider.dart:503:80)
#6 ScrollAwareImageProvider.resolveStreamForKey (package:flutter/src/widgets/scroll_aware_image_provider.dart:108:19)
#7 ImageProvider.resolve.<anonymous closure> (package:flutter/src/painting/image_provider.dart:334:9)
#8 ImageProvider._createErrorHandlerAndKey.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:464:26)
(elided 13 frames from dart:async)
Image provider: AssetImage(bundle: null, name: "")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#b540c(), name: "", scale: 1.0)
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by image resource service ════════════════════════════════════════════════
The following assertion was thrown resolving an image codec:
Unable to load asset:
When the exception was thrown, this was the stack:
#0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:223:7)
<asynchronous suspension>
#1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:669:31)
#2 AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:652:14)
#3 ImageProvider.resolveStreamForKey.<anonymous closure> (package:flutter/src/painting/image_provider.dart:505:13)
...
Image provider: AssetImage(bundle: null, name: "")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#b540c(), name: "", scale: 1.0)
════════════════════════════════════════════════════════════════════════════════════════════════════
I/zygote ( 9741): NativeAlloc concurrent copying GC freed 49007(2MB) AllocSpace objects, 12(720KB) LOS objects, 40% free, 8MB/14MB, paused 587us total 174.752ms
I/zygote ( 9741): NativeAlloc concurrent copying GC freed 18774(778KB) AllocSpace objects, 0(0B) LOS objects, 42% free, 8MB/14MB, paused 1.075ms total 187.684ms
I/zygote ( 9741): NativeAlloc concurrent copying GC freed 4679(318KB) AllocSpace objects, 0(0B) LOS objects, 42% free, 8MB/14MB, paused 22.482ms total 146.268ms
D/ ( 9741): HostConnection::get() New Host Connection established 0xa3bc5200, tid 9963
D/ ( 9741): HostConnection::get() New Host Connection established 0xa3bc5d40, tid 10271
D/ ( 9741): HostConnection::get() New Host Connection established 0x77dfe380, tid 10294