gpt4 book ai didi

java - 制造商在谷歌地图上调用相同的 Activity

转载 作者:行者123 更新时间:2023-12-02 01:18:02 24 4
gpt4 key购买 nike

我在应用 Google map 上的创客来调用 Activity 时遇到了一些问题。我可以成功创建点,甚至可以通过单击它们来调用 Activity ,但问题是,无论我做什么,它们总是调用相同的 Activity 。有人可以帮助我吗?

已经尝试移动变量,已经尝试移动 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;
}

}

关于java - 制造商在谷歌地图上调用相同的 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57646380/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com