地图显示起点。为什么不显示来自数据库的调用标记。我不明白。或者编写代码显示数据库错误?
这段代码 Map.java
public class Map extends FragmentActivity implements LocationListener {
SQLiteDatabase SQL;
GoogleMap map;
myDBClass DB;
Cursor cursor;
ArrayList<LatLng> MarkerPoint = new ArrayList<LatLng>();
double latitude = 0;
double longtitude = 0;
GMapV2Direction md = new GMapV2Direction();
Document document;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.show_map);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
if (status != ConnectionResult.SUCCESS) {
int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this,
requestCode);
dialog.show();
} else {
//map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
SupportMapFragment fm = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
map = fm.getMap();
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
map.setMyLocationEnabled(true);
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
Location location = locationManager.getLastKnownLocation(provider);
if (location != null) {
onLocationChanged(location);
}
locationManager.requestLocationUpdates(provider, 20000, 0, this);
// Destination Marker from Database SQLite
if (MarkerPoint.size() > 1) {
String Name = getIntent().getStringExtra("Name");
DB = new myDBClass(this);
SQL = DB.getWritableDatabase();
cursor = SQL.rawQuery("SELECT *" + " FROM "
+ myDBClass.TABLE_NAME + " WHERE " + myDBClass.NAME
+ " ='" + Name + "'", null);
cursor.moveToFirst();
/**String name = cursor.getString(cursor.getColumnIndex(myDBClass.NAME));
double lat_db = cursor.getDouble(cursor.getColumnIndex(myDBClass.LAT));
double lng_db = cursor.getDouble(cursor.getColumnIndex(myDBClass.LNG));
map.addMarker(new MarkerOptions()
.position(new LatLng(lat_db, lng_db)) .title(name));**/
latitude = cursor.getDouble(cursor.getColumnIndex(myDBClass.LAT));
longtitude = cursor.getDouble(cursor.getColumnIndex(myDBClass.LNG));
cursor.moveToNext();
//MarkerPoint.clear();
//map.clear();
LatLng strpoint = new LatLng(latitude, longtitude);
drawMarker(strpoint);
}
}
DrawRouteTask drawroute = new DrawRouteTask();
drawroute.execute();
}
private class DrawRouteTask extends AsyncTask<String, Void, String> {
private ProgressDialog Dialog;
String response = "";
@Override
protected void onPreExecute() {
Dialog = new ProgressDialog(Map.this);
Dialog.setMessage("Loading");
Dialog.show();
}
@Override
protected String doInBackground(String... urls) {
// Get All Route values
if (MarkerPoint.size() >= 2) {
LatLng Start = MarkerPoint.get(0);
LatLng End = MarkerPoint.get(1);
document = md.getDocument(Start, End,GMapV2Direction.MODE_DRIVING);
response = "Success";
}
return response;
}
@Override
protected void onPostExecute(String result) {
try {
if (response.equalsIgnoreCase("Success")) {
ArrayList<LatLng> directionPoint = md.getDirection(document);
PolylineOptions rectLine = new PolylineOptions().width(10).color(Color.RED);
for (int i = 0; i < directionPoint.size(); i++) {
rectLine.add(directionPoint.get(i));
}
// Adding route on the map
map.addPolyline(rectLine);
}
} catch (Exception e) {
// TODO:ERROR TRACE ROUTE
}
Dialog.dismiss();
}
}
private void drawMarker(LatLng point) {
MarkerPoint.add(point);
MarkerOptions options = new MarkerOptions();
options.position(point);
if (MarkerPoint.size() == 1) {
options.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
} else if (MarkerPoint.size() == 2) {
options.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_RED));
}
map.addMarker(options);
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
if (MarkerPoint.size() < 2) {
latitude = location.getLatitude();
longtitude = location.getLongitude();
LatLng point = new LatLng(latitude, longtitude);
map.moveCamera(CameraUpdateFactory.newLatLng(point));
map.animateCamera(CameraUpdateFactory.zoomTo(6));
drawMarker(point);
}
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
http://i.stack.imgur.com/SXq5P.jpg
地图显示起点。为什么不显示来自数据库的调用标记。我不明白。或者编写代码显示数据库错误?