I pass data of longitude and latitude from one activity to another activity, and it is successful, but how can I after received this data Display it on Google Maps as a location so the user will be see location in google map not see the number of longitude and latitude.
Note I pass data by use getExtra()
and putExtra()
If anyone know solution please help me
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(Main3Activity.this, MapsActivity.class);
intent.putExtra("Latitude", Latitude);
intent.putExtra("Longitude", Longitude);
startActivity(intent);
}
});
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
Intent i = getIntent();
final String Latitude=i.getStringExtra("Latitude");
final String Longitude=i.getStringExtra("Longitude");
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
Change
final Double Latitude=i.getStringExtra("Latitude");
final Double Longitude=i.getStringExtra("Longitude");
to
final String Latitude=i.getDoubleExtra("Latitude");
final String Longitude=i.getDoubleExtra("Longitude");
Change LatLng sydney = new LatLng(-34, 151);
to LatLng sydney = new LatLng(Latitude, Longitude);
Try this code:
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
Double Latitude=0.0;
Double Longitude=0.0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
Intent i = getIntent();
Latitude=i.getDoubleExtra("Latitude",0.0);
Longitude=i.getDoubleExtra("Longitude",0.0);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
LatLng sydney = new LatLng(Latitude, Longitude);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.