• <bdo id='q0MbL'></bdo><ul id='q0MbL'></ul>
  • <tfoot id='q0MbL'></tfoot>

      <legend id='q0MbL'><style id='q0MbL'><dir id='q0MbL'><q id='q0MbL'></q></dir></style></legend>

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

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

        Android - 无法在模拟器上获取 gps 位置

        Android - Unable to get the gps location on the emulator(Android - 无法在模拟器上获取 gps 位置)

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

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

                  <tbody id='GLvqU'></tbody>

                  <bdo id='GLvqU'></bdo><ul id='GLvqU'></ul>
                  <tfoot id='GLvqU'></tfoot>
                • <legend id='GLvqU'><style id='GLvqU'><dir id='GLvqU'><q id='GLvqU'></q></dir></style></legend>
                • 本文介绍了Android - 无法在模拟器上获取 gps 位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试在 android 模拟器上使用 gps,我有以下代码:

                  i'm tring to use the gps on the android emulator, i've the following code:

                  public class NL extends Activity {
                  
                   private LocationManager locmgr = null;
                  
                   @Override
                      public void onCreate(Bundle savedInstanceState) {
                          super.onCreate(savedInstanceState);
                          setContentView(R.layout.nl);
                  
                          locmgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
                  
                          Criteria crit = new Criteria();
                          crit.setAccuracy(Criteria.ACCURACY_FINE);
                          String provider = locmgr.getBestProvider(crit, true);
                          Location loc = locmgr.getLastKnownLocation(provider);
                  
                  
                          Toast msg = Toast.makeText(this, "Lon: " + Double.toString(loc.getLongitude()) + " Lat: " + Double.toString(loc.getLatitude()), Toast.LENGTH_SHORT);
                          msg.show();
                      }
                  }
                  

                  我在清单中添加了以下行:

                  i've added the following line at the manifest:

                  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
                  

                  我已经使用 DDMS 方法和 geo fix 方法设置了 gps 位置,但是当我运行代码时,我在 Toast 行得到一个 NullPointerExeption,可能是因为 loc 为空.

                  and i've set the gps location with the DDMS method and either with the geo fix method, but when i run the code, i get a NullPointerExeption at the Toast line, probably cause loc is null.

                  我不明白错误出在哪里...你能帮帮我吗?

                  I don't understand where the error is... can you help me please?

                  更新!

                  感谢您的帮助,现在我使用以下代码并且没有收到任何错误,但它没有运行 onChangeLocation 内的代码...它没有运行 Toast 并且不返回任何消息在日志中!

                  Thanks for your help, now i use the following code and i don't get any error, but it doesn't run the code inside onChangeLocation... it doesn't run the Toast and don't return any message in the log!

                   public class NL extends Activity {
                  
                          private LocationManager locmgr = null;
                  
                          @Override
                          public void onCreate(Bundle savedInstanceState) {
                              super.onCreate(savedInstanceState);
                              setContentView(R.layout.nl);
                  
                              locmgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
                  
                           // Define a listener that responds to location updates
                              LocationListener locationListener = new LocationListener() {
                                  public void onLocationChanged(Location loc) {
                                    // Called when a new location is found by the network location provider.
                                      Log.i("NOTIFICATION","onLocationChenged Triggered");
                  
                                      Toast msg = Toast.makeText(NetworkLocator.this, "Lon: " + Double.toString(loc.getLongitude()) + " Lat: " + Double.toString(loc.getLatitude()), Toast.LENGTH_SHORT);
                                      msg.show();
                                  }
                  
                                  public void onStatusChanged(String provider, int status, Bundle extras) {}
                  
                                  public void onProviderEnabled(String provider) {}
                  
                                  public void onProviderDisabled(String provider) {}
                                };
                  
                              // Register the listener with the Location Manager to receive location updates
                              locmgr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
                          }
                      }
                  

                  谢谢!

                  推荐答案

                  找到解决方案:

                  LocationManager.NETWORK_PROVIDER 错误.

                  LocationManager.NETWORK_PROVIDER is WRONG.

                  更正:LocationManager.GPS_PROVIDER

                  correction: LocationManager.GPS_PROVIDER

                  这篇关于Android - 无法在模拟器上获取 gps 位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Lucene Porter Stemmer not public(Lucene Porter Stemmer 未公开)
                  How to index pdf, ppt, xl files in lucene (java based or python or php any of these is fine)?(如何在 lucene 中索引 pdf、ppt、xl 文件(基于 java 或 python 或 php 中的任何一个都可以)?)
                  KeywordAnalyzer and LowerCaseFilter/LowerCaseTokenizer(KeywordAnalyzer 和 LowerCaseFilter/LowerCaseTokenizer)
                  How to search between dates (Hibernate Search)?(如何在日期之间搜索(休眠搜索)?)
                  How to get positions from a document term vector in Lucene?(如何从 Lucene 中的文档术语向量中获取位置?)
                  Java Lucene 4.5 how to search by case insensitive(Java Lucene 4.5如何按不区分大小写进行搜索)

                        <tbody id='gShoi'></tbody>

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

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

                          <bdo id='gShoi'></bdo><ul id='gShoi'></ul>
                            <legend id='gShoi'><style id='gShoi'><dir id='gShoi'><q id='gShoi'></q></dir></style></legend>