位置代码示例不起作用

时间:2011-07-15 03:30:31

标签: android android-location

我正在尝试运行下面的代码来获取用户位置(海拔/纬度/经度),但它不起作用。在logCat上,我收到以下错误消息:

07-15 02:59:47.575:ERROR / vold(26):打开开关名称路径'/ sys / class / switch / test'时出错(没有这样的文件或目录)

07-15 02:59:47.575:ERROR / vold(26):引导开关错误'/ sys / class / switch / test'(没有这样的文件或目录)

07-15 02:59:47.575:ERROR / vold(26):打开开关名称路径'/ sys / class / switch / test2'时出错(没有这样的文件或目录)

07-15 02:59:47.575:ERROR / vold(26):引导开关错误'/ sys / class / switch / test2'(没有这样的文件或目录)

07-15 03:00:15.075:ERROR / BatteryService(60):找不到usbOnlinePath

07-15 03:00:15.075:ERROR / BatteryService(60):找不到batteryVoltagePath

07-15 03:00:15.075:ERROR / BatteryService(60):找不到batteryTemperaturePath

07-15 03:00:15.134:ERROR / SurfaceFlinger(60):无法打开/ sys / power / wait_for_fb_sleep或/ sys / power / wait_for_fb_wake

07-15 03:00:25.965:ERROR / EventHub(60):无法获取/ dev / input / mouse0的驱动程序版本,不是打字机

07-15 03:00:25.975:ERROR / EventHub(60):无法获取/ dev / input / mice的驱动程序版本,不是打字机

07-15 03:00:26.404:错误/系统(60):启动核心服务失败

07-15 03:00:26.404:ERROR / System(60):java.lang.SecurityException

07-15 03:00:26.404:ERROR / System(60):在android.os.BinderProxy.transact(原生方法) 07-15 03:00:26.404:ERROR / System(60):在android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146)

07-15 03:00:26.404:ERROR / System(60):在android.os.ServiceManager.addService(ServiceManager.java:72)

07-15 03:00:26.404:ERROR / System(60):at com.android.server.ServerThread.run(SystemServer.java:176)

07-15 03:00:26.414:ERROR / AndroidRuntime(60):跳过崩溃日志,没有签到服务

07-15 03:00:49.123:ERROR / vold(26):无法启动音量'/ sdcard'(音量未绑定)

07-15 03:00:51.363:ERROR / MediaPlayerService(30):无法打开内容的fd:// settings / system / notification_sound

07-15 03:00:51.443:ERROR / MediaPlayer(60):无法创建媒体播放器

07-15 03:00:54.393:ERROR / ActivityThread(106):无法找到android.server.checkin的提供商信息

07-15 03:00:58.313:ERROR / ActivityThread(106):无法找到android.server.checkin的提供商信息

07-15 03:00:58.533:ERROR / ActivityThread(106):无法找到android.server.checkin的提供商信息

07-15 03:01:04.994:ERROR / AndroidRuntime(131):ERROR:线程附着失败

07-15 03:01:19.295:ERROR / AndroidRuntime(174):错误:线程附着失败

07-15 03:01:26.345:ERROR / ActivityThread(60):无法找到com.google.settings的提供商信息

07-15 03:01:26.355:ERROR / ActivityThread(60):无法找到com.google.settings的提供商信息

07-15 03:01:27.236:ERROR / ActivityThread(214):无法找到com.google.settings的提供商信息

07-15 03:01:27.256:ERROR / ActivityThread(214):无法找到com.google.settings的提供商信息

07-15 03:01:27.375:ERROR / ActivityThread(214):无法找到com.google.settings的提供商信息

07-15 03:01:48.195:ERROR / gralloc(60):[取消注册]句柄0x384650仍然锁定(状态= 40000001)

07-15 03:01:57.138:ERROR / ActivityThread(60):无法找到android.server.checkin的提供商信息

07-15 03:01:57.346:ERROR / gralloc(60):[取消注册]句柄0x11ee50仍然被锁定(状态= 40000001)

可能有什么不对/丢失?

清单:

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


        <application android:icon="@drawable/icon" android:label="@string/app_name">

        <uses-library android:name="com.google.android.maps" />
        <!-- uses-library android:name="android.location" /-->        
        <!--fim insercao -->    
        <activity android:name=".AppStart"
                  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>

    <uses-permission android:name="android.permission.INTERNET" />
    <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_LOCATION_EXTRA_COMMANDS" />
    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
    <uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES" />    

</manifest>

Java代码:

package net.learn2develop.Location;

import java.util.ArrayList;
import java.util.List;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;


import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

public class AppStart extends MapActivity { 
    private LocationManager myLocationManager; 
    private LocationListener myLocationListener; 
    private MapView myMapView; 
    private MapController myMapController; 
    private List<Overlay> mapOverlays;
//Button gpsON;

/** Called when the activity is first created. */
private void CenterLocation(GeoPoint centerGeoPoint) {

    mapOverlays = myMapView.getOverlays();
    myMapController.animateTo(centerGeoPoint);
    Drawable drawable = this.getResources().getDrawable(
            R.drawable.icon);
    HelloItemizedOverlay itemizedOverlay = new HelloItemizedOverlay(
            drawable, this);

    //OverlayItem overlayitem = new OverlayItem(centerGeoPoint);    
    //itemizedoverlay.addOverlay(overlayitem);
    mapOverlays.add(itemizedOverlay);

};
@Override

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    //gpsON = (Button) findViewById(R.id.mapView);    

    myMapView = (MapView) findViewById(R.id.mapView);
    myMapView.setSatellite(true);
    myMapView.setBuiltInZoomControls(true);
    // Set satellite view
    myMapController = myMapView.getController();
    myMapController.setZoom(15);

    // Fixed Zoom Level




    mapOverlays = myMapView.getOverlays();

    myLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    myLocationListener = new MyLocationListener();
    myLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,          
        0, 0, myLocationListener); 
    //myLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,            
    //        0, 0, myLocationListener); 


    // Get the current location in start-up

    GeoPoint initGeoPoint = new GeoPoint((int) (myLocationManager
            .getLastKnownLocation(LocationManager.GPS_PROVIDER)            
            .getLatitude() * 1E6), (int) (myLocationManager     
            .getLastKnownLocation(LocationManager.GPS_PROVIDER)
            .getLongitude() * 1E6));  
    CenterLocation(initGeoPoint);

}



private class MyLocationListener implements LocationListener {
    public void onLocationChanged(Location argLocation) {
        // TODO Auto-generated method stub
        GeoPoint myGeoPoint = new GeoPoint(
                (int) (argLocation.getLatitude() * 1E6),
                (int) (argLocation.getLongitude() * 1E6));
        CenterLocation(myGeoPoint);
    }

    public void onProviderDisabled(String provider) {
    // TODO Auto-generated method stub
    }

    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub
    }

public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub
    }
}

public class HelloItemizedOverlay extends ItemizedOverlay<OverlayItem> {
    private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
    private Context mContext;

    public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
        super(boundCenterBottom(defaultMarker));
    mContext = context;
    }

    public void addOverlay(OverlayItem overlay) {
        mOverlays.add(overlay);
        populate();
    }

    @Override
    protected OverlayItem createItem(int i) {
        return mOverlays.get(i);
    }

@Override
    public int size() {
        return mOverlays.size();
    }

    @Override
    protected boolean onTap(int index) {
    OverlayItem item = mOverlays.get(index);
        AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
        dialog.setTitle(item.getTitle());
        dialog.setMessage(item.getSnippet());
        dialog.show();
        return true;
    }
}

@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
    return false;
};
}

提前预订

0 个答案:

没有答案