如何像谷歌纬度一样显示指南针?

发布于 2024-12-24 02:38:27 字数 1566 浏览 2 评论 0原文

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

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

发布评论

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

评论(3

二货你真萌 2024-12-31 02:38:27

使用 MyLocationOverlay。示例代码:

public MyMapActivity extends MapActivity {
  private MyLocationOverlay myLocationOverlay;
  private MapView mapView;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.my_map_layout);

    mapView = (MapView)findViewById(R.id.map_view);

    myLocationOverlay = new MyLocationOverlay(this, mapView);
    mapView.getOverlays().add(myLocationOverlay);
  }

  @Override
  protected void onResume() {
    super.onResume();

    myLocationOverlay.enableCompass();
    myLocationOverlay.enableMyLocation();
  }

  @Override
  protected void onPause() {
    super.onPause();

    myLocationOverlay.disableCompass();
    myLocationOverlay.disableMyLocation();
  }

  @Override
  protected boolean isRouteDisplayed() {
    return false;
  }
}

Use MyLocationOverlay. Example code:

public MyMapActivity extends MapActivity {
  private MyLocationOverlay myLocationOverlay;
  private MapView mapView;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.my_map_layout);

    mapView = (MapView)findViewById(R.id.map_view);

    myLocationOverlay = new MyLocationOverlay(this, mapView);
    mapView.getOverlays().add(myLocationOverlay);
  }

  @Override
  protected void onResume() {
    super.onResume();

    myLocationOverlay.enableCompass();
    myLocationOverlay.enableMyLocation();
  }

  @Override
  protected void onPause() {
    super.onPause();

    myLocationOverlay.disableCompass();
    myLocationOverlay.disableMyLocation();
  }

  @Override
  protected boolean isRouteDisplayed() {
    return false;
  }
}
知足的幸福 2024-12-31 02:38:27

也许这个答案可以解决您旋转图标的问题:https://stackoverflow.com/a/8712727/1127492

也可以考虑为8(或16)个主要方向准备8(或16)(小!)图标,并根据方位/8(分别为)来选择图标。 /16)。

May be this answer solves your problem with rotating the icon: https://stackoverflow.com/a/8712727/1127492

You may also consider preparing 8 (or 16) (small!) icons for the 8 (or 16) main directions and select the icon depending on bearing/8 (resp. /16).

倾城°AllureLove 2024-12-31 02:38:27

Just in case somebody is facing out this problem anymore.
First of all, this needs both LocationListener and SensorEventListener. Here you can find more details of how to use it in this scope.
Anyway, Android Google Maps V2 Api partially solves this problem, displaying an arrow indicating your orientation but only when the device is moving otherway a dot will be displayed.

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