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

      <legend id='nPY6z'><style id='nPY6z'><dir id='nPY6z'><q id='nPY6z'></q></dir></style></legend>
    1. <tfoot id='nPY6z'></tfoot>
      • <bdo id='nPY6z'></bdo><ul id='nPY6z'></ul>

    2. <small id='nPY6z'></small><noframes id='nPY6z'>

        使用 Wifi 时查找当前位置有效,但使用 GPS 时失败

        时间:2023-09-01

          <tbody id='KTmXw'></tbody>

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

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

          <tfoot id='KTmXw'></tfoot>

            <bdo id='KTmXw'></bdo><ul id='KTmXw'></ul>

              • <legend id='KTmXw'><style id='KTmXw'><dir id='KTmXw'><q id='KTmXw'></q></dir></style></legend>
                1. 本文介绍了使用 Wifi 时查找当前位置有效,但使用 GPS 时失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我开发了一个使用 GPS 查找用户位置的应用程序.

                  I have developed an application to find the user's location using GPS.

                  这里没有错误.它使用 Wifi 正确找到位置,但在 GPS 模式下它不返回任何值.我在清单中添加了所需的权限,并且 GPS 已打开.

                  In this there is no error. It finds the location using Wifi correctly, but in GPS mode it doesn't return any values. I added the needed permission in the manifest and GPS is on.

                  谁能告诉我如何使用 Gps 获取位置?

                  Can someone please tell me how to get the location using Gps?

                  我在这里包含了我的代码:

                  I have included my code here:

                  package c.g.a.loation;
                  
                  public class UseGps extends Activity {
                  
                      @Override
                      public void onCreate(Bundle savedInstanceState) {
                          super.onCreate(savedInstanceState);
                          LocationManager mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
                          LocationListener mlocListener = new MyLocationListener();
                          mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
                                  mlocListener);
                      }
                  
                      /* Class My Location Listener */
                      public class MyLocationListener implements LocationListener {
                  
                          @Override
                          public void onLocationChanged(Location loc) {
                              Geocoder gp = new Geocoder(getBaseContext());
                              try {
                                  ArrayList<Address> address = (ArrayList<Address>) gp
                                          .getFromLocation(loc.getLatitude(), loc.getLongitude(),
                                                  1);
                                  if (address != null && address.size() > 0) {
                                      Toast.makeText(getBaseContext(), address.get(0).toString(),
                                              Toast.LENGTH_LONG).show();
                                  }
                              } catch (IOException e) {
                                  e.printStackTrace();
                              }
                          }
                  
                          @Override
                          public void onProviderDisabled(String provider) {}
                  
                          @Override
                          public void onStatusChanged(String arg0, int arg1, Bundle arg2) {}
                  
                          @Override
                          public void onProviderEnabled(String arg0) {}
                      }
                  
                      public void onProviderEnabled(String provider) {
                          // Toast.makeText(
                          // getApplicationContext(),"Gps Enabled",Toast.LENGTH_SHORT).show();
                      }
                  
                      public void onStatusChanged(String provider, int status, Bundle extras) {}
                  }
                  

                  推荐答案

                  我有两个想法...

                  1. 您的代码未检查以确保 GPS 提供程序已启用.我看到注释掉的代码在启用任何提供程序时发送 Toast,但您可能需要检查是否在 onCreate() 中启用了 GPS 提供程序.

                  1. Your code is not checking to make sure the GPS provider is enabled. I see commented out code send a Toast when ANY provider is enabled, but you might want to check that the GPS provider is enabled in onCreate().

                  您需要等待多长时间才能获得 GPS 位置?GPS_PROVIDER 有时可能需要一段时间才能获得 GPS 定位.我已经在两分钟前看到了 TTFF(修复拳头的时间)值.更糟糕的是,我发现不同版本的 Android 以及不同的设备在 TTFF 上存在巨大差异.

                  How long are you waiting to get the GPS location? The GPS_PROVIDER can sometimes take a while to get a GPS fix. I have seen TTFF (time to fist fix) values of over two minutes before. To make matters worse, I have seen drastic TTFF differences in different versions of Android as well as different devices.

                  我建议您也尝试从其他应用获取 GPS 定位,看看需要多长时间.我通常会启动谷歌地图或 GPS 状态(从市场上免费),以了解他们需要多长时间才能获得 GPS 修复.如果您尝试使用 Google 地图,请确保它正在获取 GPS 定位,而不仅仅是来自 NETWORK_PROVIDER 的位置(屏幕顶部的 GPS 图标应该停止闪烁).

                  I would recommend that you also try getting a GPS fix from another app to see how long that takes. I generally launch either Google Maps, or GPS Status (free from the market) to get a feeling for how long they take to get a GPS fix. If you try Google Maps, be sure that it is getting the GPS fix and not only a location from the NETWORK_PROVIDER (the GPS icon at the top of your screen should stop flashing).

                  这篇关于使用 Wifi 时查找当前位置有效,但使用 GPS 时失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:iOS 使用当前位置权限对话框在 Phonegap 应用程序中 下一篇:通过 Intent 共享照片时删除 EXIF 位置数据

                  相关文章

                  最新文章

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

                  <tfoot id='eJ0yh'></tfoot>

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