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

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

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

      Android - 如何获取当前位置(纬度和经度)?

      时间:2023-09-02

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

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

                <tbody id='shnMK'></tbody>

              • <bdo id='shnMK'></bdo><ul id='shnMK'></ul>
                本文介绍了Android - 如何获取当前位置(纬度和经度)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我正在使用以下代码获取当前位置,即(纬度和经度),但我没有获取当前位置(纬度和经度).

                I am using the following code to get the current location namely (latitude and longitude), but I am not getting current location (latitude and longitude).

                有人知道为什么吗?

                package com.ram.currentlocation;
                
                import android.app.Activity;    
                import android.content.Context;
                import android.location.Location;
                import android.location.LocationListener;
                import android.location.LocationManager;
                import android.os.Bundle;
                import android.widget.Toast;
                
                public class Location_Gps extends Activity
                {
                
                    /** Called when the activity is first created. */
                    @Override
                    public void onCreate(Bundle savedInstanceState)
                    {
                      super.onCreate(savedInstanceState);
                      setContentView(R.layout.main);
                
                      /* Use the LocationManager class to obtain GPS locations */
                      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)
                      {
                
                        loc.getLatitude();
                        loc.getLongitude();
                
                        String Text = "My current location is: " +
                        "Latitud = " + loc.getLatitude() +
                        "Longitud = " + loc.getLongitude();
                
                        Toast.makeText( getApplicationContext(), Text, Toast.LENGTH_SHORT).show();
                      }
                
                      @Override
                      public void onProviderDisabled(String provider)
                      {
                        Toast.makeText( getApplicationContext(), "Gps Disabled", Toast.LENGTH_SHORT ).show();
                      }
                
                      @Override
                      public void onProviderEnabled(String provider)
                      {
                        Toast.makeText( getApplicationContext(), "Gps Enabled", Toast.LENGTH_SHORT).show();
                      }
                
                      @Override
                      public void onStatusChanged(String provider, int status, Bundle extras)
                      {
                
                      }
                    }
                }
                

                P.S.:我在 manifest 文件中使用了以下权限:

                P.S.: I am using the following permissions in the manifest file:

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

                推荐答案

                你的清单文件有错误.正确的是:

                You have a mistake in your manifest file. Correct one is:

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

                这篇关于Android - 如何获取当前位置(纬度和经度)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:Android 地理围栏(多边形) 下一篇:在 Android 2.0+ 的 WebView 中使用 navigator.geolocation.

                相关文章

                最新文章

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

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

                  1. <legend id='tS822'><style id='tS822'><dir id='tS822'><q id='tS822'></q></dir></style></legend>
                  2. <small id='tS822'></small><noframes id='tS822'>