尝试访问Android位置数据时出现问题

时间:2013-02-21 03:45:21

标签: android gps location

所以我正在为我的手机尝试一个简单的Lat Long。 我正在使用我自己的手机进行测试,该手机在FirmWare Level 2.3.6上。

这是主要代码:

import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;

public class MainActivity extends FragmentActivity {
    private LocationManager locationManager = null;
    private LocationListener locationListener = null;

    // private LocationListener onLocationChange=null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        locationManager = (LocationManager) this
                .getSystemService(Context.LOCATION_SERVICE);
        locationListener = new MyLocationListener();

        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
                0, locationListener);
        locationManager.requestLocationUpdates(
                LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
        System.out.println("I got here");

    }

    public class MyLocationListener implements LocationListener {
        @Override
        public void onLocationChanged(Location loc) {
            /*
             * System.out.println("This happened"); String message =
             * "Longitude:" + loc.getLongitude() + "  Latitude: " +
             * loc.getLongitude(); Toast.makeText( getBaseContext(),
             * "Location changed: Lat: " + loc.getLatitude() + " Lng: " +
             * loc.getLongitude(), Toast.LENGTH_SHORT).show();
             */
            System.out.println("IN ON LO

CATION CHANGE, lat="
                    + loc.getLatitude() + ", lon=" + loc.getLongitude());
        }

        @Override
        public void onProviderDisabled(String arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProviderEnabled(String arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
            // TODO Auto-generated method stub

        }

    }

}

这是清单

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.cloud.pushpin.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>

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyArmkmqy3i-wNsVH0f8RH15OsaR4lv4Sp8" />
    </application>

    <permission
        android:name="com.cloud.pushpin.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.cloud.pushpin.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

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

</manifest>

基本上我所看到的是,当我启动应用程序时没有任何反应。当我摇动手机时,我收到了“我来到这里”的消息很多次,但从来没有经纬度显示。我不明白为什么回调没有发生。其他权限适用于我实施google maps api后。手机上启用了GPS以及移动数据。

0 个答案:

没有答案