【问题标题】:I cant get latitude and longitude in lollipop.It works fine in other versions and maximum sdk is 22我无法在棒棒糖中获得纬度和经度。它在其他版本中运行良好,最大 sdk 为 22
【发布时间】:2015-04-14 10:32:26
【问题描述】:

我无法在棒棒糖中获得纬度和经度。它在姜饼和 kitkat 等其他版本中运行良好,最大 sdk 为 22。我已经给出了

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.project2"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="22" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Java 代码。

package com.example.project2;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.widget.TextView;

import android.util.Log;

 public class MainActivity extends Activity implements LocationListener {
 // The minimum distance to change Updates in meters
 private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 1; // 1 meters
 // The minimum time between updates in milliseconds
private static final long MIN_TIME_BW_UPDATES = 1000 * 10 * 1; // 10 sec
protected LocationManager locationManager;
protected Context context;
protected boolean gps_enabled, network_enabled;
TextView txtLat;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtLat = (TextView) findViewById(R.id.t1);

locationManager =  (LocationManager)getSystemService(Context.Location_Service);          
// getting GPS status
gps_enabled = locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);
// getting network status
 network_enabled=locationManager.isProviderEnabled(LocationManager.NETWORK_PROVID   ER);

if (gps_enabled) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
} else if (network_enabled) {
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
};
} 

   @Override
   public void onLocationChanged(Location location) {
   txtLat = (TextView) findViewById(R.id.t1);
   txtLat.setText("Latitude:"+ location.getLatitude() + ", Longitude:"
    + location.getLongitude());
    }

    @Override
    public void onProviderDisabled(String provider) {
    Log.d("Latitude", "disable");
    }

    @Override
    public void onProviderEnabled(String provider) {
     Log.d("Latitude", "enable");
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras){                
    Log.d("Latitude", "status");
   }
   }

我是在 Eclipse Juno 中完成的。我的主要目的是获取位置并发送到我提供的另一部手机。但首先我没有得到任何位置。

【问题讨论】:

  • 您是否遇到任何强制关闭或它只是返回 0 0 纬度和经度...??
  • 把你用来获取经纬度的代码放在这里。
  • 检查 Lollipop 设备中是否安装了 Google Play 服务库?
  • 老兄,这段代码没有人能帮助你......
  • 不,我没有收到任何强制关闭错误@Gowtham Raj

标签: android location android-permissions


【解决方案1】:

请通过以下链接。

Location issue with lollipop

Retrieve current location

它可以帮助你。如果没有,请告诉我。

【讨论】:

    【解决方案2】:

    避免使用这种老方法,看看Making Your App Location-Aware

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-09
      • 1970-01-01
      • 1970-01-01
      • 2015-09-12
      • 1970-01-01
      • 2017-07-08
      • 2015-09-10
      相关资源
      最近更新 更多