当前位置: 代码迷 >> Android >> Android GPS位置获取 为何总是不能运行?
  详细解决方案

Android GPS位置获取 为何总是不能运行?

热度:14   发布时间:2016-05-01 12:17:10.0
Android GPS位置获取 为什么总是不能运行??!!!
在网上找了各个版本的GPS定位,可是都不能运行!要么是Sorry,the application has stopped unexpectly.Please try agian.要么就是在DDMS send经纬度之后毫无反应……哭……
到底哪里出了问题?请各位大侠们指点!不胜感激!
下面是源码:
MainActivity.java


package com.se7en;

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.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
/** Called when the activity is first created. */
private Button button = null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        button = (Button)findViewById(R.id.locationButtonId);
        button.setOnClickListener(new ButtonListener());
    }
    
  private class ButtonListener implements OnClickListener{
  
  @Override
  public void onClick(View v){
  LocationManager locationManager = (LocationManager)MainActivity.this.getSystemService(Context.LOCATION_SERVICE);
  locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new TestLocationListener());
  }
  }
    
    private class TestLocationListener implements LocationListener{
    
    
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
System.out.println(location.getLongitude());
System.out.println(location.getLatitude());
}

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

}

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

}

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

}
    
    }
}

manifest 文件

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

    <uses-sdk android:minSdkVersion="10" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".Location1Activity"
  相关解决方案