【问题标题】:MapBox User Location Icon (Android)MapBox 用户位置图标 (Android)
【发布时间】:2016-02-12 04:17:34
【问题描述】:

我将 MapBox 用于我的 Android 应用程序,我需要修改用于指示当前用户位置和方向的标准蓝色“点”。

我发现这个线程表明过去的 MapBox Android API 提供了修改用户位置图标的方法: https://github.com/mapbox/mapbox-android-sdk-legacy/issues/717

线程提到了这些方法:

mapView.getUserLocationOverlay().setDirectionArrowBitmap();
mapView.getUserLocationOverlay().setPersonBitmap();

最新的 MapBox Android SDK 没有显示这些方法。有谁知道这些方法的替代品或修改用户位置图标的替代品?

maven 存档在这里:http://grepcode.com/file/repo1.maven.org/maven2/com.mapbox.mapboxsdk/mapbox-android-sdk/0.7.4/com/mapbox/mapboxsdk/overlay/UserLocationOverlay.java#UserLocationOverlay.setDirectionArrowBitmap%28com.mapbox.mapboxsdk.overlay.Bitmap%29

【问题讨论】:

    标签: android api geolocation mapbox


    【解决方案1】:

    MapBox 回应了澄清这些方法的替代品的请求,并表示:

    至于更改自定义标记的位置以显示运动,最好的办法是在需要显示进度时添加和删除标记。根据您需要多快刷新位置,这种方法可能看起来有点不稳定,但这是目前最好的解决方法。这将通过

    MapView.addMarker()
    

    MapView.removeAnnotation()
    

    这不是一个理想的解决方案,但现在应该可以完成工作。

    【讨论】:

      【解决方案2】:

      我添加了一个巴士图标,您可以随意更改它。

          @SuppressWarnings({"MissingPermission"})
      private void enableLocationComponent(@NonNull Style loadedMapStyle) {
          // Check if permissions are enabled and if not request
          if (PermissionsManager.areLocationPermissionsGranted(mainActivity)) {
              // Activate the MapboxMap LocationComponent to show user location
              // Adding in LocationComponentOptions is also an optional parameter
              locationComponent = mapboxMap.getLocationComponent();
              locationComponent.activateLocationComponent(mainActivity, loadedMapStyle);
              locationComponent.setLocationComponentEnabled(true);
      
              // Create and customize the LocationComponent's options
              LocationComponentOptions customLocationComponentOptions = LocationComponentOptions.builder(getActivity())
                      .foregroundDrawable(R.drawable.bus)
                      .build();
      
      
              // Get an instance of the component
              locationComponent = mapboxMap.getLocationComponent();
      
              LocationComponentActivationOptions locationComponentActivationOptions =
                      LocationComponentActivationOptions.builder(getActivity(), loadedMapStyle)
                              .locationComponentOptions(customLocationComponentOptions)
                              .build();
      
              // Activate with options
              locationComponent.activateLocationComponent(locationComponentActivationOptions);
      
              // Set the component's camera mode
              locationComponent.setCameraMode(CameraMode.TRACKING);
      
              //  IconFactory iconFactory = IconFactory.getInstance(getActivity());
              //  mapboxMap.addMarker(new MarkerOptions().icon(iconFactory.fromResource(R.drawable.bus)));
      
          } else {
              permissionsManager = new PermissionsManager(this);
              permissionsManager.requestLocationPermissions(mainActivity);
          }
      }
      

      【讨论】:

        【解决方案3】:

        标记表示地图上的单个位置。您可以通过更改默认颜色或将标记图标替换为自定义图像来自定义标记。信息窗口可以为标记提供额外的上下文。

        MarkerView markerView = new MarkerView(new LatLng(LAT,LONG), customView);
                                                     
        markerViewManager.addMarker(markerView);
                                                    
        mapView.getMapAsync(new OnMapReadyCallback() {
            @Override
            public void onMapReady(MapboxMap mapboxMap) {                                 
                MarkerViewManager markerViewManager = new MarkerViewManager(mapView, mapboxMap);
                                                     
            }
        });
        

        markerViewManager.removeMarker(markerView);

        废话不多说,让我们看看 好的,我们会检查的 这里什么都没有。 如果你看到 你需要 我会检查并回复 现在你可以 别担心

        @Volatile
        synchronized intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK.or(Intent.FLAG_ACTIVITY_CLEAR_TASK)
        
        // for Log 
        public static final String TAG = MyApplication.class.getSimpleName();       
        
                     
                                        
                                
                                
                              
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-01-24
          相关资源
          最近更新 更多