flutter地图框地图显示/布局问题在Android上

发布于 2025-01-30 07:41:04 字数 6265 浏览 1 评论 0原文

我是Flutter的新手,并试图将MAPBOX MAP与iOS和Android应用中的转弯导航进行集成。

我正在使用 flutter_mapbox_navigation 软件包和 mapboxNavigationView

  • ios:按预期工作 “

  • Android API 30:Mapbox徽标似乎表明窗口小部件在正确的位置,但是在正确的位置,但是地图本身不在

  • Android API 27、28和29:地图似乎显示正确,但是Mapbox徽标不可见,对我来说,这仍然表明某物仍然关闭 “

  • android api 26:MAP和MAPBOX徽标在正确位置可见 “

  • Android API 24和25:Mapbox logo在正确的位置,但MAP在MAP上不可见。全部 “

我尝试了不同的方法来尺寸和定位窗口,但问题仍然存在。

我尝试使用Flutter小部件检查员,但据我所知,一切似乎都不错。 我尝试使用Android Studio布局,但看到了一个空白页。

我已经找到了这个线程,但是没有解决方案 mapbox Map在Android上未显示

我在Macos Monterey 12.3.1(Apple M1)

Main.dart

import 'package:flutter/material.dart';
import 'package:flutter_mapbox_navigation/library.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  MyApp({Key? key}) : super(key: key);

  final _options = MapBoxOptions();
  Future<void> _onRouteEvent(e) async {}

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Column(
        children: [
          const Text("test"),
          Center(
            child: SizedBox(
              width: 300,
              height: 200,
              child: MapBoxNavigationView(
                options: _options,
                onRouteEvent: _onRouteEvent,
                onCreated: (MapBoxNavigationViewController controller) async {},
              ),
            ),
          ),
        ],
      ),
    );
  }
}

Pubspec.yml

name: poc
description: A new Flutter project.

# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1

environment:
  sdk: ">=2.17.0 <3.0.0"

# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
# consider running `flutter pub upgrade --major-versions`. Alternatively,
# dependencies can be manually updated by changing the version numbers below to
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
  flutter:
    sdk: flutter


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2
  flutter_mapbox_navigation: ^0.0.26

dev_dependencies:
  flutter_test:
    sdk: flutter

  # The "flutter_lints" package below contains a set of recommended lints to
  # encourage good coding practices. The lint set provided by the package is
  # activated in the `analysis_options.yaml` file located at the root of your
  # package. See that file for information about deactivating specific lint
  # rules and activating additional ones.
  flutter_lints: ^2.0.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter packages.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  # assets:
  #   - images/a_dot_burr.jpeg
  #   - images/a_dot_ham.jpeg

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware

  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages

I am new to Flutter and trying to integrate a MapBox map with Turn by Turn navigation in an iOS and Android app.

I am using the flutter_mapbox_navigation package and MapBoxNavigationView.

  • iOS: Works as expected
    screenshot iOS simulator

  • Android API 30: the mapbox logo seems to indicate that the widget is at the right place but the map itself is off

screenshot android emulator API 30

  • Android API 27, 28 and 29: The map seems to show correctly, but the MapBox logo is not visible, which to me indicates that something is still off
    screenshot android emulator API 29

  • Android API 26: map and MapBox logo visible at the right location
    screenshot android emulator API 26

  • Android API 24 and 25: MapBox logo at the right position but map is not visible at all
    screenshot android emulator API 24

I have tried different ways of sizing and positionning the widget but the issue remains.

I have tried using Flutter widget inspector but everything seems fine as far as I can tell.
I have tried using Android Studio Layout but I see a blank page.

I have found this thread but there is no solution Mapbox Map not showing on android

I am on macOS Monterey 12.3.1 (Apple M1)

main.dart

import 'package:flutter/material.dart';
import 'package:flutter_mapbox_navigation/library.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  MyApp({Key? key}) : super(key: key);

  final _options = MapBoxOptions();
  Future<void> _onRouteEvent(e) async {}

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Column(
        children: [
          const Text("test"),
          Center(
            child: SizedBox(
              width: 300,
              height: 200,
              child: MapBoxNavigationView(
                options: _options,
                onRouteEvent: _onRouteEvent,
                onCreated: (MapBoxNavigationViewController controller) async {},
              ),
            ),
          ),
        ],
      ),
    );
  }
}

pubspec.yml

name: poc
description: A new Flutter project.

# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1

environment:
  sdk: ">=2.17.0 <3.0.0"

# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
# consider running `flutter pub upgrade --major-versions`. Alternatively,
# dependencies can be manually updated by changing the version numbers below to
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
  flutter:
    sdk: flutter


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2
  flutter_mapbox_navigation: ^0.0.26

dev_dependencies:
  flutter_test:
    sdk: flutter

  # The "flutter_lints" package below contains a set of recommended lints to
  # encourage good coding practices. The lint set provided by the package is
  # activated in the `analysis_options.yaml` file located at the root of your
  # package. See that file for information about deactivating specific lint
  # rules and activating additional ones.
  flutter_lints: ^2.0.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter packages.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  # assets:
  #   - images/a_dot_burr.jpeg
  #   - images/a_dot_ham.jpeg

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware

  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

指尖上的星空 2025-02-06 07:41:04

找到了解决方案。

我删除了 flutter_mapbox_navigation 包装和使用Platform> Platform> Platform> PlatformView。起初我仍然遇到同样的问题,但是后来我发现了textureView选项,这解决了我的问题。

val resourceOptions = ResourceOptions.Builder()
            .accessToken(context.getString(R.string.mapbox_access_token))
            .build()

mapView = MapView(context, MapInitOptions(context, resourceOptions).apply { textureView = true })

Found a solution.

I removed the flutter_mapbox_navigation package and reimplemented Android integration by hand using a PlatformView. At first I still had the same issue, but then I found about the textureView option and this solved my problem.

val resourceOptions = ResourceOptions.Builder()
            .accessToken(context.getString(R.string.mapbox_access_token))
            .build()

mapView = MapView(context, MapInitOptions(context, resourceOptions).apply { textureView = true })
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文