Basic gps problems

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Basic gps problems

Postby android devloper » Thu Aug 13, 2009 7:53 am

Hello guys,

I am new to android n i hv got problem with gps application.i will post the code ....there are no errors....bt nothing is being displayed...
i'am just trying to print the coordinates of my current location...a basic gps application in one of the books on android.

package com.gps;
import android.view.View;
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;

public class gps extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
LocationManager locationManager;
String context = Context.LOCATION_SERVICE;
locationManager = (LocationManager)getSystemService(context);
String provider = LocationManager.GPS_PROVIDER;
Location location = locationManager.getLastKnownLocation(provider);
updateWithNewLocation(location);
}
private void updateWithNewLocation(Location location) {
String latLongString;
TextView myLocationText;
myLocationText = (TextView)findViewById(R.id.TextView01);
if (location != null) {
double lat = location.getLatitude();
double lng = location.getLongitude();
latLongString = "Lat:" + lat + "\nLong:" + lng;
} else {
latLongString = "No location found";
}
myLocationText.setText("Your Current Position is:\n" +
latLongString);
}
}



wat am i missing..... please help me out....thanks in advance...
android devloper
Freshman
Freshman
 
Posts: 4
Joined: Sun Jul 26, 2009 8:28 am

Top

Postby stifry » Thu Aug 13, 2009 11:52 pm

Your class needs to implement LocationListener and methods. Then you need register your activity with the locationmanager:

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
Visit Trackaroo.com!
Trackmaster - Motorsports Lap Timer
Dynomaster - Performance Dyno
Image Image
User avatar
stifry
Developer
Developer
 
Posts: 46
Joined: Tue Feb 17, 2009 7:50 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 4 guests