Reputation: 56
I'm trying to bundle form main_activity to google_maps_activity. The bundle contains a string and the string contains an float with coordinates, latitude and longitude.
I think my bundle is fine, but when i open my app it opens Google Maps with the default coordinates (0, 0). Any suggestions on what i can do? Or do differently?
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
Intent map_aktivitet = getIntent();
Bundle bundle = map_aktivitet.getExtras();
String sett_longitude = bundle.getString("longitude");
float sett_longitude2 = bundle.getFloat(sett_longitude);
String sett_latitude = bundle.getString("latitude");
float sett_latitude2 = bundle.getFloat(sett_latitude);
String name = bundle.getString("textViewName");
LatLng home = new LatLng(sett_latitude2, sett_longitude2);
mMap.addMarker(new MarkerOptions().position(home).title("Here lives " + name));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(home, 16));
}
Upvotes: 0
Views: 749
Reputation: 5550
Use Double
to parse marker
, marker
accept double
:,
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
String sett_longitude = getIntent().getStringExtra("longitude");
double sett_longitude2 = Double.parseDouble(sett_longitude);
String sett_latitude = getIntent().getStringExtra("latitude");
double sett_latitude2 = Double.parseDouble(sett_latitude);
String name = bundle.getString("textViewName");
LatLng home = new LatLng(sett_latitude2, sett_longitude2);
mMap.addMarker(new MarkerOptions().position(home).title("Here lives " + name));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(home, 16));
}
Upvotes: 0
Reputation: 1193
String sett_longitude = bundle.getString("longitude");
float sett_longitude2 = bundle.getFloat(sett_longitude);
String sett_latitude = bundle.getString("latitude");
float sett_latitude2 = bundle.getFloat(sett_latitude);
this is completely wrong...
try this
String sett_longitude = bundle.getString("longitude");
float sett_longitude2 = Float.parseFloat(sett_longitude);
String sett_latitude = bundle.getString("latitude");
float sett_latitude2 = Float.parseFloat(sett_latitude);
Upvotes: 1