我在将制造商应用到Google地图上进行通话活动时遇到了一些问题。
我可以成功创建点,甚至可以通过单击它们来调用活动,但是问题是,无论我做什么,它们总是调用相同的活动。
有人能帮我吗?
已经尝试移动变量,已经尝试移动celula01变量以查看是否建立了连接,但是这些都没有返回任何结果。
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap, mCel;
@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(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mCel = googleMap;
LatLng celula04 = new LatLng(-23.174601, -45.839513);
mCel.addMarker(new MarkerOptions().position(celula04).title("Célula da Maria"));
mCel.moveCamera(CameraUpdateFactory.newLatLng(celula04));
mCel.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener(){
@Override
public boolean onMarkerClick(Marker marker) {
Intent intent = new Intent(MapsActivity.this, Celula02.class);
startActivity(intent);
return false;
}
});
LatLng celula01 = new LatLng(-23.173300, -45.821273);
mMap.addMarker(new MarkerOptions().position(celula01).title("Célula do Rafael"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(celula01));
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener(){
@Override
public boolean onMarkerClick(Marker marker) {
Intent intent = new Intent(MapsActivity.this, Celula01.class);
startActivity(intent);
return false;
}
});
}
}
谢谢。
最佳答案
public class MapsActivity extends FragmentActivity implements
OnMarkerClickListener,
OnMapReadyCallback {
private static final LatLng celula04 = new LatLng(-23.174601, -45.839513);
private static final LatLng celula01 = new LatLng(-23.173300, -45.821273);
private Marker mcelula04;
private Marker mcelula01;
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.marker_demo);
SupportMapFragment mapFragment =
(SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
/** Called when the map is ready. */
@Override
public void onMapReady(GoogleMap map) {
mMap = map;
// Add some markers to the map, and add a data object to each marker.
mcelula04 = mMap.addMarker(new MarkerOptions()
.position(celula04)
.title("Célula da Maria");
mcelula04.setTag(1);
mcelula01 = mMap.addMarker(new MarkerOptions()
.position(celula01)
.title("Célula do Rafael");
mcelula01.setTag(2);
// Set a listener for marker click.
mMap.setOnMarkerClickListener(this);
}
/** Called when the user clicks a marker. */
@Override
public boolean onMarkerClick(final Marker marker) {
// Retrieve the data from the marker.
Integer click = (Integer) marker.getTag();
// Check if a click count was set, then display the click count.
if (click = 1) {
public boolean onMarkerClick(Marker marker) {
Intent intent = new Intent(MapsActivity.this, Celula02.class);
startActivity(intent);
}elseif(click = 2){
Intent intent = new Intent(MapsActivity.this, Celula01.class);
startActivity(intent);
}
// Return false to indicate that we have not consumed the event and that we wish
// for the default behavior to occur (which is for the camera to move such that the
// marker is centered and for the marker's info window to open, if it has one).
return false;
}
}