0
私はOnInfoWindowClickListenerを使用しようとしています。ユーザーがマーカーの情報ウィンドウをタップすると、私はPageActivityという名前の別のアクティビティに移動します。しかし、私がオンラインで見つけたすべての実装はうまくいかないようで、Googleマップのapiドキュメントで提供されていたレイアウトはうまくいかないようでした。 はまた、ライン mMap.setOnInfoWindowClickListener(新しいOnInfoWindowClickListener(){コードの下部に 、赤思い付く、特に新しいOnInfoWindowClickListener()OnInfoWindowClickListenerの実装
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@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;
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
mMap.setMyLocationEnabled(true);
}
// Add a marker in Sydney and move the camera
//mMap.addMarker(new MarkerOptions().position(new LatLng(0,0)).title("Lets try this").snippet("gotcha"));
//LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
//Location myLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
//mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
//double user_latitude = myLocation.getLatitude();
//double user_longitude = myLocation.getLongitude();
//LatLng user_coord = new LatLng(user_latitude, user_longitude);
//mMap.animateCamera(CameraUpdateFactory.zoomTo(14));
//mMap.addMarker(new MarkerOptions().position(new LatLng(user_latitude,user_longitude)).title("You are here"));
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
Location location = locationManager.getLastKnownLocation(provider);
if (location != null) {
LatLng target = new LatLng(location.getLatitude(), location.getLongitude());
CameraPosition position = this.mMap.getCameraPosition();
CameraPosition.Builder builder = new CameraPosition.Builder();
builder.zoom(15);
builder.target(target);
this.mMap.animateCamera(CameraUpdateFactory.newCameraPosition(builder.build()));
//Marker our_marker = mMap.addMarker(new MarkerOptions().position(new LatLng(location.getLatitude(), location.getLongitude())).title("Local Bathroom").snippet("Tap for Rating").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
Intent intent = new Intent(MapsActivity.this, DummyContent.class);
startActivity(intent);
} });
}
//LatLng New_york = new LatLng(40, -73);
LatLng netherlands = new LatLng(40.715613, -73.604853);
LatLng studentcenter1 = new LatLng(40.715946, -73.602037);
LatLng studentcenter2 = new LatLng(40.716231, -73.601007);
LatLng bits = new LatLng(40.713889, -73.601651);
LatLng playhouse = new LatLng(40.713043, -73.600707);
LatLng calkins = new LatLng(40.713303, -73.599977);
LatLng axinn = new LatLng(40.714824, -73.600492);
LatLng library = new LatLng(40.714609, -73.601116);
LatLng alliance = new LatLng(40.716502, -73.602183);
//mMap.addMarker(new MarkerOptions().position(New_york).title("Welcome to the city!!"));
Marker alliance_marker = mMap.addMarker(new MarkerOptions().position(alliance).title("Alliance Hall's Bathroom").snippet("Tap for Rating").icon(BitmapDescriptorFactory.fromResource(R.drawable.finaltoilet)));
Marker library_marker = mMap.addMarker(new MarkerOptions().position(library).title("Axinn Library's Bathroom").snippet("Tap for Rating").icon(BitmapDescriptorFactory.fromResource(R.drawable.finaltoilet)));
Marker Hammer_marker = mMap.addMarker(new MarkerOptions().position(axinn).title("Hammer Lab's Bathroom").snippet("Tap for Rating").icon(BitmapDescriptorFactory.fromResource(R.drawable.finaltoilet)));
Marker calkins_marker = mMap.addMarker(new MarkerOptions().position(calkins).title("Calkins Hall's Bathroom").snippet("Tap for Rating").icon(BitmapDescriptorFactory.fromResource(R.drawable.finaltoilet)));
Marker playhouse_marker = mMap.addMarker(new MarkerOptions().position(playhouse).title("Playhouse's Bathroom").snippet("Tap for Rating").icon(BitmapDescriptorFactory.fromResource(R.drawable.finaltoilet)));
Marker bits_marker = mMap.addMarker(new MarkerOptions().position(bits).title("Bits and Bite's Bathroom").snippet("Tap for Rating").icon(BitmapDescriptorFactory.fromResource(R.drawable.finaltoilet)));
Marker studentcenter2_marker = mMap.addMarker(new MarkerOptions().position(studentcenter2).title("Game Room's Bathroom").snippet("Tap for Rating").icon(BitmapDescriptorFactory.fromResource(R.drawable.finaltoilet)));
Marker studentcenter1_marker = mMap.addMarker(new MarkerOptions().position(studentcenter1).title("Student Center's Bathroom").snippet("Tap for Rating").icon(BitmapDescriptorFactory.fromResource(R.drawable.finaltoilet)));
Marker netherlands_marker = mMap.addMarker(new MarkerOptions().position(netherlands).title("Netherland's Bathroom").snippet("Tap for Rating").icon(BitmapDescriptorFactory.fromResource(R.drawable.finaltoilet)));
Marker our_marker = mMap.addMarker(new MarkerOptions().position(new LatLng(location.getLatitude(), location.getLongitude())).title("Local Bathroom").snippet("Tap for Rating").icon(BitmapDescriptorFactory.fromResource(R.drawable.finaltoilet)));
mMap.setOnMarkerClickListener((GoogleMap.OnMarkerClickListener) this);
//mMap.moveCamera(CameraUpdateFactory.newLatLng(New_york));
}
mMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
public void onInfoWindowClick(Marker marker) {
Intent intent = new Intent(MapsActivity.this, PageActivity.class);
startActivity(intent);
}
});
}