Hello all, nice to meet you guys
I am developing a program that including the GPS function
but I program it for 2 days and still got error
so, could you mind to give me some hints?
here are my code.
package com.fyp.android.blindsystem;
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.widget.Toast;
public class Check_Location extends Activity implements LocationListener{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.check_location);
Bundle bundle = this.getIntent().getExtras();
Toast.makeText(Check_Location.this,bundle.getStrin g("User_id"), Toast.LENGTH_SHORT).show();
showLocation();
}
@Override //When location is changed
public void onLocationChanged(Location location) {
Toast.makeText(this, location.toString(), Toast.LENGTH_LONG).show();
}
@Override //When User turns off GPS or AGPS
public void onProviderDisabled(String provider) {
}
@Override //When Users turn on GPS or AGPS
public void onProviderEnabled(String provider) {
}
@Override //When GPS or AGPS is changed
public void onStatusChanged(String provider, int status, Bundle extras) {
}
private LocationManager mgr;
private void showLocation(){
mgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location location = mgr.getLastKnownLocation("gps");
StringBuffer msg = new StringBuffer();
msg.append("Latitude: ");
msg.append(Double.toString(location.getLatitude()) ); //get error at here
msg.append(", Longitude: ");
msg.append(Double.toString(location.getLongitude() ));
Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
}
}
Manifest setting
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fyp.android.blindsystem"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".BlindSystem"
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="Service"
android:label="@string/service_title">
</activity>
<activity android:name="Check_Location"
android:label="Your location is">
</activity>
</application>
<uses-sdk android:minSdkVersion="3" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOC ATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCAT ION"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>
Thanks!!
Does anyone can help me plx?
Thanks alot
Bookmarks