我试图让我的标记显示出来。显然,我必须编码 但是,我从未尝试过使用更新的json对象作为我标记的坐标。我正在利用自己的知识来构建此活动,但所有显示的都是地图。我没有任何错误。
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
JSONParser jsonparser = new JSONParser();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(map);
mapFragment.getMapAsync(this);
//调用Retrievedata
new Retrievedata().execute();
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady( GoogleMap googleMap) {
mMap = googleMap;
Marker marker;
class Retrievedata extends AsyncTask<Void, Double, Void> {
@Override
protected Void doInBackground(Void... params) {
try {
while (!isCancelled()) {
jobj = jsonparser.makeHttpRequest("http://api.wheretheiss.at/v1/satellites/25544");
Double lat = jobj.getDouble("latitude");
Double longit = jobj.getDouble("longitude");
// this will cause onProgressUpdate to be called with lat & long
publishProgress(lat, longit);
// it's okay to sleep within the background thread
Thread.sleep(1500);
}
} catch (InterruptedException e) {
Log.w("RetrieveData", "thread was interrupted", e);
} catch (JSONException e) {
Log.e("RetrieveData", "parse error", e);
}
return null;
}
@Override
public void onProgressUpdate(Double... values) {
Marker marker;
marker = mMap.addMarker(new MarkerOptions()
.position(new LatLng(values[0], values[1]))
.title("ISS")
.snippet(""));
}
}
}
protected void onResume(){
super.onResume();
}
protected void onDestroy(){
super.onDestroy();
}
}