onLocationChanged不叫检索位置 [英] onLocationChanged not called to retrieve position

查看:202
本文介绍了onLocationChanged不叫检索位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在开发使用 Google地图API ,现在它工作得很好到我的app.Few天前用来测试我的实际设备应用程序我做我的平板电脑的硬复位,当我试图再次测试我的应用程序,这并不像before.so我logcat中我看到 locationClient 连接工作,但它不能识别我的位置,所以 onLocationChanged 永远不会被调用。

I' m developing an app that use the google maps api, now it worked fine into my real device which i used to the test the app.Few days ago i made an hard reset on my tablet and when i tried to test my app again, it didn't work as before.so in my logcat i see that the locationClient is connected, but it can't recognize my position, so onLocationChanged is never called.

我注意到这一点到我logcat的:

i notice this into my logcat:

I/Google Maps Android API(2924): Google Play services client version: 5089000
I/Google Maps Android API(2924): Google Play services package version: 5089032

我知道,这是两个不同版本的谷歌播放服务,我可以不知道如何解决它,因为之前平板电脑的硬复位,我没有得到这个信息到logcat的。

i know that these are two different versions of google play services, i can't understand how to fix it, because before tablet's hard reset,i hadn't got this info into logcat.

这是我的manifest.xml:

this is my manifest.xml:

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

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="19" />

    <permission
        android:name="com.logic.main.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.logic.main.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.MyAppTheme" >
        <activity
            android:name="com.logic.main.MainActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.logic.maps.activity.MapsActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/app_name" >
        </activity>

        <service
            android:name="com.logic.maps.backgroundService.LocationBackgroundService"
            android:enabled="true" >
        </service>

        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="MyApiKey" />
    </application>

</manifest>

活动:

public class MapsActivity extends Activity implements GooglePlayServicesClient.ConnectionCallbacks, GooglePlayServicesClient.OnConnectionFailedListener,
        LocationListener, OnInfoWindowClickListener, OnMarkerClickListener {

    private static final long UPDATE_INTERVAL = 5000;
    private static final long FASTEST_INTERVAL = 1000;

    private GoogleMap map = null;
    private LocationClient locationClient;
    private Location myLocation;
    private LocationRequest locationRequest;
    private LatLng newPosition;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map);
        map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
        map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        locationClient = new LocationClient(this, this, this);
        locationRequest = LocationRequest.create().setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY).setInterval(UPDATE_INTERVAL)
                .setFastestInterval(FASTEST_INTERVAL).setSmallestDisplacement(10);
        if (locationClient != null)
            // connect the client to the Google Play services
            locationClient.connect();
    }

    @Override
    public void onLocationChanged(Location location) {
        //THIS IS NEVER CALLED
        newPosition = new LatLng(location.getLatitude(), location.getLongitude());
        myLocation = location;
        map.animateCamera(CameraUpdateFactory.newLatLngZoom(newPosition, 15));
    }

    @Override
    public void onConnected(Bundle arg0) {
        //*************************** AT THE BEGINNING THIS IS CALLED***************/
        // BUT onLocationChanged is never called
        Toast.makeText(this, "I'm bringing you to your area.", Toast.LENGTH_SHORT).show();
        locationClient.requestLocationUpdates(locationRequest, this);
    }

    @Override
    public void onDisconnected() {
        Toast.makeText(this, "Disconnected. Please re-connect.", Toast.LENGTH_SHORT).show();
    }

    [...]
}

感谢您的帮助。

推荐答案

安装最新的谷歌从Android SDK管理器播放服务

Install the latest Google Play Services from the Android SDK manager

这篇关于onLocationChanged不叫检索位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆