mirror of
https://github.com/googlemaps/android-samples.git
synced 2025-12-08 18:02:20 +00:00
Merge branch 'marker-retap-info-window-close2'
This commit is contained in:
commit
1a1db6cf08
@ -23,5 +23,5 @@ dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
testCompile 'junit:junit:4.12'
|
||||
compile 'com.android.support:appcompat-v7:23.4.0'
|
||||
compile 'com.google.android.gms:play-services-maps:9.6.0'
|
||||
compile 'com.google.android.gms:play-services-maps:9.8.0'
|
||||
}
|
||||
|
||||
@ -99,6 +99,9 @@
|
||||
<activity
|
||||
android:name=".MarkerDemoActivity"
|
||||
android:label="@string/marker_demo_label"/>
|
||||
<activity
|
||||
android:name=".MarkerCloseInfoWindowOnRetapDemoActivity"
|
||||
android:label="@string/marker_close_info_window_on_retap_demo_label"/>
|
||||
<activity
|
||||
android:name=".MultiMapDemoActivity"
|
||||
android:label="@string/multi_map_demo_label"/>
|
||||
|
||||
@ -65,6 +65,9 @@ public final class DemoDetailsList {
|
||||
new DemoDetails(R.string.marker_demo_label,
|
||||
R.string.marker_demo_description,
|
||||
MarkerDemoActivity.class),
|
||||
new DemoDetails(R.string.marker_close_info_window_on_retap_demo_label,
|
||||
R.string.marker_close_info_window_on_retap_demo_description,
|
||||
MarkerCloseInfoWindowOnRetapDemoActivity.class),
|
||||
new DemoDetails(R.string.multi_map_demo_label,
|
||||
R.string.multi_map_demo_description,
|
||||
MultiMapDemoActivity.class),
|
||||
|
||||
@ -0,0 +1,148 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.mapdemo;
|
||||
|
||||
import com.google.android.gms.maps.CameraUpdateFactory;
|
||||
import com.google.android.gms.maps.GoogleMap;
|
||||
import com.google.android.gms.maps.GoogleMap.OnMapClickListener;
|
||||
import com.google.android.gms.maps.GoogleMap.OnMarkerClickListener;
|
||||
import com.google.android.gms.maps.OnMapReadyCallback;
|
||||
import com.google.android.gms.maps.SupportMapFragment;
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.google.android.gms.maps.model.LatLngBounds;
|
||||
import com.google.android.gms.maps.model.Marker;
|
||||
import com.google.android.gms.maps.model.MarkerOptions;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
/**
|
||||
* This shows how to close the info window when the currently selected marker is re-tapped.
|
||||
*/
|
||||
public class MarkerCloseInfoWindowOnRetapDemoActivity extends AppCompatActivity implements
|
||||
OnMarkerClickListener,
|
||||
OnMapReadyCallback,
|
||||
OnMapClickListener {
|
||||
|
||||
private static final LatLng BRISBANE = new LatLng(-27.47093, 153.0235);
|
||||
private static final LatLng MELBOURNE = new LatLng(-37.81319, 144.96298);
|
||||
private static final LatLng SYDNEY = new LatLng(-33.87365, 151.20689);
|
||||
private static final LatLng ADELAIDE = new LatLng(-34.92873, 138.59995);
|
||||
private static final LatLng PERTH = new LatLng(-31.952854, 115.857342);
|
||||
|
||||
private GoogleMap mMap = null;
|
||||
|
||||
/**
|
||||
* Keeps track of the selected marker.
|
||||
*/
|
||||
private Marker mSelectedMarker;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.marker_close_info_window_on_retap_demo);
|
||||
|
||||
SupportMapFragment mapFragment =
|
||||
(SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
|
||||
mapFragment.getMapAsync(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapReady(GoogleMap map) {
|
||||
mMap = map;
|
||||
|
||||
// Hide the zoom controls.
|
||||
mMap.getUiSettings().setZoomControlsEnabled(false);
|
||||
|
||||
// Add lots of markers to the map.
|
||||
addMarkersToMap();
|
||||
|
||||
// Set listener for marker click event. See the bottom of this class for its behavior.
|
||||
mMap.setOnMarkerClickListener(this);
|
||||
|
||||
// Set listener for map click event. See the bottom of this class for its behavior.
|
||||
mMap.setOnMapClickListener(this);
|
||||
|
||||
// Override the default content description on the view, for accessibility mode.
|
||||
// Ideally this string would be localized.
|
||||
map.setContentDescription("Demo showing how to close the info window when the currently"
|
||||
+ " selected marker is re-tapped.");
|
||||
|
||||
LatLngBounds bounds = new LatLngBounds.Builder()
|
||||
.include(PERTH)
|
||||
.include(SYDNEY)
|
||||
.include(ADELAIDE)
|
||||
.include(BRISBANE)
|
||||
.include(MELBOURNE)
|
||||
.build();
|
||||
mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 50));
|
||||
}
|
||||
|
||||
private void addMarkersToMap() {
|
||||
mMap.addMarker(new MarkerOptions()
|
||||
.position(BRISBANE)
|
||||
.title("Brisbane")
|
||||
.snippet("Population: 2,074,200"));
|
||||
|
||||
mMap.addMarker(new MarkerOptions()
|
||||
.position(SYDNEY)
|
||||
.title("Sydney")
|
||||
.snippet("Population: 4,627,300"));
|
||||
|
||||
mMap.addMarker(new MarkerOptions()
|
||||
.position(MELBOURNE)
|
||||
.title("Melbourne")
|
||||
.snippet("Population: 4,137,400"));
|
||||
|
||||
mMap.addMarker(new MarkerOptions()
|
||||
.position(PERTH)
|
||||
.title("Perth")
|
||||
.snippet("Population: 1,738,800"));
|
||||
|
||||
mMap.addMarker(new MarkerOptions()
|
||||
.position(ADELAIDE)
|
||||
.title("Adelaide")
|
||||
.snippet("Population: 1,213,000"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapClick(final LatLng point) {
|
||||
// Any showing info window closes when the map is clicked.
|
||||
// Clear the currently selected marker.
|
||||
mSelectedMarker = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMarkerClick(final Marker marker) {
|
||||
// The user has re-tapped on the marker which was already showing an info window.
|
||||
if (marker.equals(mSelectedMarker)) {
|
||||
// The showing info window has already been closed - that's the first thing to happen
|
||||
// when any marker is clicked.
|
||||
// Return true to indicate we have consumed the event and that we do not want the
|
||||
// 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).
|
||||
mSelectedMarker = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
mSelectedMarker = marker;
|
||||
|
||||
// Return false to indicate that we have not consumed the event and that we wish
|
||||
// for the default behavior to occur.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -22,7 +22,6 @@ import com.google.android.gms.maps.OnMapReadyCallback;
|
||||
import com.google.android.gms.maps.SupportMapFragment;
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.google.android.gms.maps.model.MapStyleOptions;
|
||||
import com.google.android.gms.maps.model.MarkerOptions;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2016 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
<fragment
|
||||
android:id="@+id/map"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
class="com.google.android.gms.maps.SupportMapFragment"/>
|
||||
</LinearLayout>
|
||||
@ -80,6 +80,8 @@
|
||||
<string name="map_in_pager_demo_label">Map In Pager</string>
|
||||
<string name="map_in_pager_demo_description">Demonstrates how to add a map to a ViewPager.</string>
|
||||
<string name="marker_demo_label">Markers</string>
|
||||
<string name="marker_close_info_window_on_retap_demo_label">Marker Close Info Window on Retap</string>
|
||||
<string name="marker_close_info_window_on_retap_demo_description">Demonstrates how to close the info window when the currently selected marker is retapped.</string> <string name="marker_demo_label">Markers</string>
|
||||
<string name="marker_demo_description">Demonstrates how to add Markers to a map.</string>
|
||||
<string name="move_the_camera">Move the camera</string>
|
||||
<string name="multi_map_demo_label">Multiple Maps</string>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user