Cannot pass coordinates to map

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

Cannot pass coordinates to map

Postby Pauled » Sun Jun 12, 2011 7:24 pm

Hi all,

I'm new to android apps, I have read through various books and now attempting to develop my first app. I have successfully managed to get the app to display a simple map with zoom features, but now I am trying to get updated coordinates from the LocationManager with little success. Here is my Java code:

package com.first.android.locationfinder;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;

import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;

public class Main extends MapActivity {
/** Called when the activity is first created. */

// Acquire a reference to the system Location Manager
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
MapController mControl;
GeoPoint GeoP;
MapView mapV;

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

mapV = (MapView) findViewById(R.id.mapView);
mapV.displayZoomControls(true);
mapV.setBuiltInZoomControls(true);

LocationListener locationListener = new locationListener();
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);

//double lat = 51.555313;
//double longi = -2.571902;

//GeoP = new GeoPoint ((int) (lat *1E6), (int) (longi *1E6));

//mControl = mapV.getController();
//mControl.animateTo(GeoP);
//mControl.setZoom(13);
}

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


public class locationListener implements LocationListener{

@Override
public void onLocationChanged(Location loc){
loc.getLatitude();
loc.getLongitude();
GeoP = new GeoPoint ((int) (loc.getLatitude() *1E6), (int) (loc.getLongitude() *1E6));

mControl = mapV.getController();
mControl.animateTo(GeoP);
mControl.setZoom(13);
}

@Override
public void onProviderDisabled(String provider){
//Display GPS disable error message
}


@Override
public void onProviderEnabled(String provider){
//GPS enabled
}


@Override
public void onStatusChanged(String provider, int status, Bundle extras) {

}

}/* End of Class locationListener */

}



the couple of lines commented out are lines I used to generate the map, which I have now moved into the locationListener, so that it updates with new information. Any feedback or assistance is greatly appreciated. :)
Pauled
Freshman
Freshman
 
Posts: 2
Joined: Sun Jun 12, 2011 7:16 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 1 guest