Ich möchte meine Arraylist mit den Koordinaten, die ich in meiner MainActivity auf Google Maps in meiner Google Maps-Aktivität habe, ausfüllen. Wie kann ich das am einfachsten machen? My for-Schleife die JSON-Daten zu erhalten:Wie kann ich meine Arraylist mit Koordinaten auf Google Maps anzeigen?
for (int j = 0; j <= 10; j++) {
JSONObject marker = placemarks.getJSONObject(j);
JSONArray coordinates = marker.optJSONArray("coordinates");
double lat = coordinates.optDouble(0);
double lng = coordinates.optDouble(1);
latlongList.add(new LatLng(lat, lng));
}
Meine aktuelle Google Maps Aktivität:
public class CarLocation extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_car2_go_location);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
/**
* 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) {
MainActivity mainActivity = new MainActivity();
mMap = googleMap;
// Add a marker in Hamburg and move the camera
LatLng hamburg = new LatLng(53.551086, 9.993682);
mMap.addMarker(new MarkerOptions().position(hamburg).title("Marker in Hamburg"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(hamburg));
}
}
Sie möchten latlongList an die Autostandort-Aktivität übergeben? – Blackkara
Ja, wenn es möglich ist. Und danach möchte ich es auf Google Maps anzeigen – Jade
Ja möglich, aber wenn Sie latlongList verwenden, nur um Marker zu erstellen. Sie können JSON-Betrieb in CarLocation vornehmen und verwenden, anstatt von einer anderen Aktivität zu senden. Überprüfe meinen Beitrag. – Blackkara