我试图添加并显示从JSON对象解析的多个标记。 在LOG中,我检查了所有lat长点是否正确,但是当我试图将标记添加到该latlong点时,标记没有显示。
这是我的代码
public class MapsEarthquakeMapActivity extends Activity {
// Coordinates used for centering the Map
private static final double CAMERA_LNG = 87.0;
private static final double CAMERA_LAT = 17.0;
// The Map Object
private GoogleMap mMap;
private final static String URL = "xyzz";
public static final String TAG = "MapsEarthquakeMapActivity";
// Set up UI and get earthquake data
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
new HttpGetTask().execute(URL);
}
private class HttpGetTask extends
AsyncTask<String, Void, List<EarthQuakeRec>> {
AndroidHttpClient mClient = AndroidHttpClient.newInstance("");
@Override
protected List<EarthQuakeRec> doInBackground(String... params) {
HttpGet request = new HttpGet(params[0]);
JSONResponseHandler responseHandler = new JSONResponseHandler();
try {
// Get Earthquake data in JSON format
// Parse data into a list of EarthQuakeRecs
return mClient.execute(request, responseHandler);
} catch (ClientProtocolException e) {
Log.i(TAG, "ClientProtocolException");
} catch (IOException e) {
Log.i(TAG, "IOException");
}
return null;
}
@SuppressLint("NewApi")
@Override
protected void onPostExecute(List<EarthQuakeRec> result) {
// Get Map Object
mMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
if (null != mMap) {
// Add a marker for every earthquake
for (EarthQuakeRec rec : result) {
Log.v("pointM", "" + rec.getPoint());
Log.v("NAMES", "" + rec.getName());
String point = rec.getPoint();
String[] latlng = point.split(",");
String lat = latlng[0];
String lng = latlng[1];
Double lat1 = Double.parseDouble(lat);
Double lng1 = Double.parseDouble(lng);
Log.v("LATLNGM", "" + lat + "&" + lng);
// Add a new marker for this earthquake
mMap.addMarker(new MarkerOptions().position(
new LatLng(lat1, lng1)).title(rec.getName()));
}
mMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(
CAMERA_LAT, CAMERA_LNG)));
}
if (null != mClient)
mClient.close();
}
}
}
这是我进入Log
03-26 08:46:21.975: V/LATLNGM(5193): 77.583690&12.930022
03-26 08:46:22.067: V/LATLNGM(5193): 77.585996&12.932729
03-26 08:46:22.099: V/LATLNGM(5193): 77.595369&12.926995
03-26 08:46:22.139: V/LATLNGM(5193): 77.592627&12.918970
03-26 08:46:22.163: V/LATLNGM(5193): 77.574011&12.935930
03-26 08:46:22.187: V/LATLNGM(5193): 77.564679&12.927071
03-26 08:46:22.203: V/LATLNGM(5193): 77.570388&12.946059
03-26 08:46:22.203: V/LATLNGM(5193): 77.580569&12.956148
03-26 08:46:22.203: V/LATLNGM(5193): 77.564076&12.908918
03-26 08:46:22.203: V/LATLNGM(5193): 77.559660&12.941591
我哪里出错.. ?? 请帮帮我。
感谢所有