Help, which owns the source code for retrieving data of latitude and
longitude of the sqlite database and display them on google maps? I
did this and it does not work: (
=>this code gives me just google maps and markers is not: (
DBAdapter.java
public ArrayList<Station> getPositions() {
//ajouteStation();
ArrayList <Station> output = new ArrayList<Station>();
String[] colonnesARecup = new String[] {
"_id",
"nom",
"position_x",
"position_y"
};
Cursor cursorResults = db.query("stations", colonnesARecup,
null,
null, null, null, null);
if (null != cursorResults) {
if (cursorResults.moveToFirst()) {
do {
int id =
cursorResults.getInt(cursorResults.getColumnIndex("_id"));
String
nom=cursorResults.getString(cursorResults.getColumnIndex("nom"));
Double
position_x=cursorResults.getDouble(cursorResults.getColumnIndex("position_x"));
Double
position_y=cursorResults.getDouble(cursorResults.getColumnIndex("position_y"));
Station station=new Station(id, nom,
position_x, position_y);
output.add(station);
} while (cursorResults.moveToNext());
} // end-if
} // end-if
db.close();
return output;
}
LigneTransport.java,
public class LigneTransport extends MapActivity{
MapView mapView = null;
private double lat = 0;
private double lng = 0;
DBAdapter db;
MapItimizedOverlay positionMarkersList;
private MapController mc;
private GeoPoint location;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lignesss);
//db = new DBAdapter(this);
// db.open();
// DataBind();
// Configure la map
try{
configureMapView();
retrieveAndDisplayPositions();
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
/*private void DataBind() {
// TODO Auto-generated method stub
db.Truncate();
Cursor c=db.recuprerLaListeStations();
startManagingCursor(c);
}*/
private void configureMapView() {
mapView = (MapView) findViewById(R.id.map1);
mapView.setBuiltInZoomControls(true);
this.mapView.setClickable(true);
mc = mapView.getController();
lat = 36.844461;
lng = 10.151367;
this.location = new GeoPoint((int) (lat * 1E6), (int)
(lng *
1E6));
mc.animateTo(location);
mc.setCenter(location);
mc.setZoom(17);
//this.mapView.setSatellite(true);
this.mapView.invalidate();
}
public GeoPoint getLocation() {
return location;
}
public void setLocation(GeoPoint location) {
this.location = location;
this.mc.setCenter(this.location);
this.mapView.invalidate();
}
private void retrieveAndDisplayPositions() {
// Affiche l'ensemble des marqueurs enregistrés en DB
{
positionMarkersList = new
MapItimizedOverlay(this.getResources().getDrawable(R.drawable.marker),
this);
final List<Overlay> mapOverlays = mapView.getOverlays();
mapOverlays.add(positionMarkersList);
// Récupère de la DB les marqueurs enregistrés
// et ajoute les à la carte
{
final DBAdapter dbHelp = new
DBAdapter(getApplicationContext());
for (final Station positionToAdd : dbHelp.getPositions())
{
addPosition(positionToAdd);
} // end-for
} // end-block
} // end-block
}
private void addPosition(Station station) {
double lat = station.getPosition_x();
double lng = station.getPosition_y();
GeoPoint geoPoint = new GeoPoint((int) (lat * 1E6), (int) (lng
* 1E6));
OverlayItem overlayitem = new OverlayItem(geoPoint, null,
null);
positionMarkersList.addOverlay(overlayitem);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en