• <legend id='6PzqN'><style id='6PzqN'><dir id='6PzqN'><q id='6PzqN'></q></dir></style></legend>
  • <i id='6PzqN'><tr id='6PzqN'><dt id='6PzqN'><q id='6PzqN'><span id='6PzqN'><b id='6PzqN'><form id='6PzqN'><ins id='6PzqN'></ins><ul id='6PzqN'></ul><sub id='6PzqN'></sub></form><legend id='6PzqN'></legend><bdo id='6PzqN'><pre id='6PzqN'><center id='6PzqN'></center></pre></bdo></b><th id='6PzqN'></th></span></q></dt></tr></i><div id='6PzqN'><tfoot id='6PzqN'></tfoot><dl id='6PzqN'><fieldset id='6PzqN'></fieldset></dl></div>
    <tfoot id='6PzqN'></tfoot>

          <bdo id='6PzqN'></bdo><ul id='6PzqN'></ul>

        <small id='6PzqN'></small><noframes id='6PzqN'>

      1. onLocationChanged 不会自动调用

        时间:2023-09-02

          <small id='qh3U1'></small><noframes id='qh3U1'>

        1. <tfoot id='qh3U1'></tfoot>
            <bdo id='qh3U1'></bdo><ul id='qh3U1'></ul>

              <tbody id='qh3U1'></tbody>
            • <i id='qh3U1'><tr id='qh3U1'><dt id='qh3U1'><q id='qh3U1'><span id='qh3U1'><b id='qh3U1'><form id='qh3U1'><ins id='qh3U1'></ins><ul id='qh3U1'></ul><sub id='qh3U1'></sub></form><legend id='qh3U1'></legend><bdo id='qh3U1'><pre id='qh3U1'><center id='qh3U1'></center></pre></bdo></b><th id='qh3U1'></th></span></q></dt></tr></i><div id='qh3U1'><tfoot id='qh3U1'></tfoot><dl id='qh3U1'><fieldset id='qh3U1'></fieldset></dl></div>

              1. <legend id='qh3U1'><style id='qh3U1'><dir id='qh3U1'><q id='qh3U1'></q></dir></style></legend>
                  本文介绍了onLocationChanged 不会自动调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我对 Android 中的 onLocationChanged 事件有疑问.这是触发:

                  I have a problem with onLocationChanged event in Android. Here's the triggering:

                  case R.id.start: {
                      Points.add(overlay.getMyLocation()); // Points' type is ArrayList<GeoPoint>
                      mgr.requestLocationUpdates(best, 0, 3, locationListener);
                      }
                      break;
                  

                  这是 onLocationChanged 方法:

                  And here's the onLocationChanged method:

                  public void onLocationChanged(Location location) {
                      i++;
                      Points.add(overlay.getMyLocation());
                      MapOverlay mapOverlay = new MapOverlay(Points.get(i-1), Points.get(i));
                      map.getOverlays().add(mapOverlay); //does the drawing
                      mMapController.animateTo(Points.get(i));
                  }
                  

                  因此,onLocationChanged 仅在我按下开始"后才被调用一次.它应该在每次位置更改时自动调用,对吗?在我的情况下,它不是.
                  请帮帮我.

                  So, onLocationChanged is called only once and only after I press "start". It's supposed to be called automatically every time the location has changed, right? In my case, it's not.
                  Please help me.

                  推荐答案

                  问题似乎解决了.在 onCreate 中,我添加了:

                  Problem seems to be solved. In onCreate, I added:

                  Criteria crit = new Criteria();
                  crit.setAccuracy(Criteria.ACCURACY_FINE);
                  best = mgr.getBestProvider(crit, false);
                  mgr.requestLocationUpdates(best, 0, 1, locationListener);
                  

                  onLocationChanged 现在看起来像这样:

                  onLocationChanged now looks like that:

                  @Override
                  public void onLocationChanged(Location location) {
                      i++;
                      nextPoint = overlay.getMyLocation();
                      latitude = nextPoint.getLatitudeE6();
                      longtitude = nextPoint.getLongitudeE6();
                      lastPoint = new GeoPoint((int) latitude, (int) longtitude);
                      Points.add(lastPoint);
                      MapOverlay mapOverlay = new MapOverlay(Points.get(i - 1), Points.get(i));
                      map.getOverlays().add(mapOverlay);
                      mMapController.animateTo(Points.get(i));
                      nextPoint = null;
                      lastPoint = null;
                  }
                  

                  另外,非常重要的方法:

                  Also, very important methods:

                  @Override
                  protected void onResume() {
                      super.onResume();
                      mgr.requestLocationUpdates(best, 10000, 1, locationListener);
                  }
                  
                  @Override
                  protected void onPause() {
                      super.onPause();
                      mgr.removeUpdates(locationListener);
                  }
                  

                  还有一些新的权限:

                  <uses-permission android:name="android.permission.ACCESS_GPS" />
                          <uses-permission android:name="android.permission.ACCESS_LOCATION" />
                          <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
                          <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
                          <uses-permission android:name="android.permission.INTERNET" />
                  

                  这篇关于onLocationChanged 不会自动调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:科尔多瓦地理定位精度上限为 10 米 下一篇:android上的javascript地理定位不起作用

                  相关文章

                  最新文章

                  1. <tfoot id='wlIyM'></tfoot>

                      • <bdo id='wlIyM'></bdo><ul id='wlIyM'></ul>
                    1. <small id='wlIyM'></small><noframes id='wlIyM'>

                      <i id='wlIyM'><tr id='wlIyM'><dt id='wlIyM'><q id='wlIyM'><span id='wlIyM'><b id='wlIyM'><form id='wlIyM'><ins id='wlIyM'></ins><ul id='wlIyM'></ul><sub id='wlIyM'></sub></form><legend id='wlIyM'></legend><bdo id='wlIyM'><pre id='wlIyM'><center id='wlIyM'></center></pre></bdo></b><th id='wlIyM'></th></span></q></dt></tr></i><div id='wlIyM'><tfoot id='wlIyM'></tfoot><dl id='wlIyM'><fieldset id='wlIyM'></fieldset></dl></div>
                      <legend id='wlIyM'><style id='wlIyM'><dir id='wlIyM'><q id='wlIyM'></q></dir></style></legend>