嵌入式MAPBOX导航
我正在为电动汽车的智能显示器制作一个扑朔迷离的应用程序。因此,想法是拥有2个材料应用程序:一个用于整个应用程序,另一个仅用于导航,以便我只能在负责导航的一部分内将不同的页面推到不同的页面(IE ProgreRide屏幕,HomeScreen,TurnbyTurnScreen .. 。)如您所见。因此,一切看起来都不错,我可以选择启动和端点地址,但问题是导航立即全屏幕,但是我需要将其留在屏幕的右侧。 mainscreen
任何人都有一个想法如何解决这个问题?
相关代码给出了波纹管(我没有放入“ 未来_ONROUTEEVENT(e)async {} ”功能,因为它是标准的,那里没什么特别的)。如您所见,我在地图加载时使用了SiziedBox作为圆形ProgressIndicator。我希望我的导航也可以适合或类似的盒子。
import 'package:evo_app_nav/helpers/shared_prefs.dart';
import 'package:flutter/material.dart';
import 'package:mapbox_gl/mapbox_gl.dart';
import 'package:flutter_mapbox_navigation/library.dart';
class TurnByTurn extends StatefulWidget {
const TurnByTurn({Key? key}) : super(key: key);
@override
State<TurnByTurn> createState() => _TurnByTurnState();
}
class _TurnByTurnState extends State<TurnByTurn> {
// Waypoints to mark trip start and end
LatLng source = getTripLatLngFromSharedPrefs('source');
LatLng destination = getTripLatLngFromSharedPrefs('destination');
late WayPoint sourceWaypoint, destinationWaypoint;
var waypoints = <WayPoint>[];
// Config variables for Mapbox Navigation
late MapBoxNavigation directions;
late MapBoxOptions _options;
late double distanceRemaining, durationRemaining;
late MapBoxNavigationViewController _controller;
final bool isMultipleStop = false;
String instruction = "";
bool arrived = false;
bool routeBuilt = false;
bool isNavigating = false;
@override
void initState() {
super.initState();
initialize();
}
Future<void> initialize() async {
if (!mounted) return;
// Setup directions and options
directions = MapBoxNavigation(onRouteEvent: _onRouteEvent);
_options = MapBoxOptions(
zoom: 18,
voiceInstructionsEnabled: true,
bannerInstructionsEnabled: true,
mode: MapBoxNavigationMode.drivingWithTraffic,
isOptimized: true,
units: VoiceUnits.metric,
simulateRoute: true,
language: 'en',
);
// Configure waypoints
sourceWaypoint = WayPoint(
name: "Source", latitude: source.latitude, longitude: source.longitude);
destinationWaypoint = WayPoint(
name: "Destination",
latitude: destination.latitude,
longitude: destination.longitude);
waypoints.add(sourceWaypoint);
waypoints.add(destinationWaypoint);
// Start the trip
await directions.startNavigation(wayPoints: waypoints, options: _options);
}
@override
Widget build(BuildContext context) {
//return const RateRide();
return SizedBox(
width: 300, height: 400, child: const CircularProgressIndicator());
}
I'm making an flutter app for my electric vehicle's smart display. So the idea is to have 2 MaterialApps: one for the whole app, and another one only for navigation so that I can push different pages only inside a part of the screen that is responsible for navigation (i.e. prepareRide screen, homeScreen, turnByTurnScreen ...) as you can see bellow. So, everything looks fine, I can select starting and endpoint address but THE PROBLEM IS THAT NAVIGATION IMMEDIATELY GOES FULL SCREEN, but I need it to stay embedded on the right part of the screen. mainScreen
ANYBODY HAS AN IDEA HOW TO SOLVE THIS ISSUE ?
Relevant code is given bellow (I did not put "Future _onRouteEvent(e) async {}" function here because it is standard, nothing special there). As you can see I used SizedBox for CircularProgressIndicator while the map is loading. I would like that my navigation also can fit that or similiar box.
import 'package:evo_app_nav/helpers/shared_prefs.dart';
import 'package:flutter/material.dart';
import 'package:mapbox_gl/mapbox_gl.dart';
import 'package:flutter_mapbox_navigation/library.dart';
class TurnByTurn extends StatefulWidget {
const TurnByTurn({Key? key}) : super(key: key);
@override
State<TurnByTurn> createState() => _TurnByTurnState();
}
class _TurnByTurnState extends State<TurnByTurn> {
// Waypoints to mark trip start and end
LatLng source = getTripLatLngFromSharedPrefs('source');
LatLng destination = getTripLatLngFromSharedPrefs('destination');
late WayPoint sourceWaypoint, destinationWaypoint;
var waypoints = <WayPoint>[];
// Config variables for Mapbox Navigation
late MapBoxNavigation directions;
late MapBoxOptions _options;
late double distanceRemaining, durationRemaining;
late MapBoxNavigationViewController _controller;
final bool isMultipleStop = false;
String instruction = "";
bool arrived = false;
bool routeBuilt = false;
bool isNavigating = false;
@override
void initState() {
super.initState();
initialize();
}
Future<void> initialize() async {
if (!mounted) return;
// Setup directions and options
directions = MapBoxNavigation(onRouteEvent: _onRouteEvent);
_options = MapBoxOptions(
zoom: 18,
voiceInstructionsEnabled: true,
bannerInstructionsEnabled: true,
mode: MapBoxNavigationMode.drivingWithTraffic,
isOptimized: true,
units: VoiceUnits.metric,
simulateRoute: true,
language: 'en',
);
// Configure waypoints
sourceWaypoint = WayPoint(
name: "Source", latitude: source.latitude, longitude: source.longitude);
destinationWaypoint = WayPoint(
name: "Destination",
latitude: destination.latitude,
longitude: destination.longitude);
waypoints.add(sourceWaypoint);
waypoints.add(destinationWaypoint);
// Start the trip
await directions.startNavigation(wayPoints: waypoints, options: _options);
}
@override
Widget build(BuildContext context) {
//return const RateRide();
return SizedBox(
width: 300, height: 400, child: const CircularProgressIndicator());
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否正在使用Flutter_Mapbox_navigation: ^0.2.2?
如果是,我有2个视图,即出现的视图,当我单击一个按钮时,它将继续进行完整地图视图,
以便这是我的实现
返回(扩展了)(
孩子:mapboxNavigationView(
选项:_navigationOption,
OnRouteevent:_ONEMBEDDEDROUTEEVENT,
发出的:
(MapBoxNavigationViewControllloll Controller)async {
_controller =控制器;
Controller.Initialize();
//单击按钮后,它将导航到全屏幕地图导航
返回MAPBOX导航视图时构建路由的功能
}
//
are you using flutter_mapbox_navigation: ^0.2.2 ?
if yes, i I have 2 views, the one that comes up, and when I click a button, it then proceeds to full map view
so this is my Implementation
return Expanded(
child: MapBoxNavigationView(
options: _navigationOption,
onRouteEvent: _onEmbeddedRouteEvent,
onCreated:
(MapBoxNavigationViewController controller) async {
_controller = controller;
controller.initialize();
//once the button is clicked it navigates to full-screen map navigation
//function to build the route when the Mapbox navigation view is returned
}
feel free to ask for more clarification