下面列出了怎么用com.google.android.gms.maps.model.MapStyleOptions的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l)
{
if (adapterView.getId() == R.id.sMapType)
{
googleMap.setMapType(mapTypes[i]);
} else if (adapterView.getId() == R.id.sMapStyle)
{
try
{
googleMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(this, mapStyles[i]));
} catch (Exception exc)
{
googleMap.setMapStyle(null);
}
}
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.getUiSettings().setZoomControlsEnabled(true);
mMap.getUiSettings().setZoomGesturesEnabled(true);
mMap.setInfoWindowAdapter(new CustomInfoWindow(this));
googleMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(this, R.raw.uber_style_map));
mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng latLng) {
if(destinationMarker!=null)
destinationMarker.remove();
destinationMarker=mMap.addMarker(new MarkerOptions().position(latLng)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_destination_marker))
.title("Destination"));
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15.0f));
BottomSheetRiderFragment mBottomSheet=BottomSheetRiderFragment.newInstance(String.format("%f,%f", currentLat, currentLng),
String.format("%f,%f",latLng.latitude, latLng.longitude), true);
mBottomSheet.show(getSupportFragmentManager(), mBottomSheet.getTag());
}
});
mMap.setOnInfoWindowClickListener(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
boolean success = googleMap.setMapStyle(new MapStyleOptions(getResources()
.getString(R.string.style_json)));
if (!success) {
Log.e("Style", "Style parsing failed.");
}
LatLng jakarta = new LatLng(-6.232812, 106.820933);
LatLng southjakarta = new LatLng(-6.22865,106.8151753);
mMap.addMarker(new MarkerOptions().position(jakarta).icon(BitmapDescriptorFactory.fromBitmap(getBitmapFromView("Set Pickup Location", R.drawable.dot_pickup))));
mMap.addMarker(new MarkerOptions().position(southjakarta).icon(BitmapDescriptorFactory.fromBitmap(getBitmapFromView("Set Dropoff Location", R.drawable.dot_dropoff))));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(jakarta, 15f));
}
protected MapStyleOptions getMapStyle() {
if (mStyleEnum == NiboStyle.CUSTOM) {
if (mStyleFileID != DEFAULT_MARKER_ICON_RES) {
return MapStyleOptions.loadRawResourceStyle(
getActivity(), mStyleFileID);
} else {
throw new IllegalStateException("NiboStyle.CUSTOM requires that you supply a custom style file, you can get one at https://snazzymaps.com/explore");
}
} else if (mStyleEnum == NiboStyle.DEFAULT) {
return null;
} else {
if (mStyleEnum == null) {
return null;
}
{
return MapStyleOptions.loadRawResourceStyle(
getActivity(), mStyleEnum.getValue());
}
}
}
private void setMapStyle() {
if (currentIndex == rawArray.length && rawArray.length != 0) {
currentIndex = 0;
}
try {
mMap.setMapStyle(
MapStyleOptions.loadRawResourceStyle(
this, rawArray[currentIndex++]));
} catch (Resources.NotFoundException e) {
Log.e("MapsActivity", "Cannot find style.", e);
}
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setTrafficEnabled(false);
mMap.setIndoorEnabled(false);
mMap.setBuildingsEnabled(false);
mMap.getUiSettings().setZoomControlsEnabled(true);
googleMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(this, R.raw.uber_style_map));
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
googleMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(this, R.raw.uber_style_map));
settingInformation();
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
boolean success = googleMap.setMapStyle(new MapStyleOptions(getResources()
.getString(R.string.style_json)));
if (!success) {
Log.e("Style", "Style parsing failed.");
}
LatLng jakarta = new LatLng(-6.232812, 106.820933);
mMap.addMarker(new MarkerOptions().position(jakarta).icon(BitmapDescriptorFactory.fromBitmap(getBitmapFromView("Set Pickup Location", R.drawable.dot_pickup))));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(jakarta, 15f));
}
/**
* Call this method to build the GoogleMapStyler
*
* @return GoogleMapStyler
*/
public GoogleMapStyler build() {
if (json.length() > 1) {
json = json.deleteCharAt(json.length() - 1);
}
json = json.append("]");
String temp = json.toString().replaceAll("\\\\", "");
googleMapStyler.setMapStyleOptions(new MapStyleOptions(temp));
return googleMapStyler;
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
MapStyleOptions style = MapStyleOptions.loadRawResourceStyle(mContext, R.raw.map_style);
mMap.setMapStyle(style);
checkPermissions();
configureMapClickListener();
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
MapStyleOptions style = MapStyleOptions.loadRawResourceStyle(mContext, R.raw.map_style);
mMap.setMapStyle(style);
checkPermissions();
configureMapClickListener();
}
/**
* Shortcut for applying this style to a {@link GoogleMap}.
*
* @param map The {@link GoogleMap} object to style.
*/
void applyToMap(GoogleMap map) {
try {
map.setMapStyle(new MapStyleOptions(mJson.getString("json")));
} catch (JSONException e) {
Log.e(TAG, e.toString());
}
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
/*LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));*/
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
mMap.setMyLocationEnabled(true);
mMap.setTrafficEnabled(true);
mMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(this, R.raw.mapstyle_night));
/**
* UNCOMMENT TO TEST setLatLngBoundsForCameraTarget
*
*
* final LatLngBounds ADELAIDE = new LatLngBounds(
new LatLng(-35.0, 138.58), new LatLng(-34.9, 138.61));
final CameraPosition ADELAIDE_CAMERA = new CameraPosition.Builder()
.target(new LatLng(-34.92873, 138.59995)).zoom(20.0f).bearing(0).tilt(0).build();
mMap.setLatLngBoundsForCameraTarget(ADELAIDE);
mMap.addMarker(new MarkerOptions()
.position(new LatLng(-34.92873, 138.59995))
.title("My Marker"));
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(ADELAIDE_CAMERA));
**
*/
}
@Override
public void onMapReady(GoogleMap map) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
map.setMapType(preferences.getInt(getString(R.string.baseLayerKey), getResources().getInteger(R.integer.baseLayerDefaultValue)));
int dayNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
if (dayNightMode == Configuration.UI_MODE_NIGHT_NO) {
map.setMapStyle(null);
} else {
map.setMapStyle(MapStyleOptions.loadRawResourceStyle(getApplicationContext(), R.raw.map_theme_night));
}
if (latLng != null && icon != null) {
map.addMarker(new MarkerOptions()
.position(latLng)
.icon(icon));
LocationProperty accuracyProperty = location.getPropertiesMap().get("accuracy");
if (accuracyProperty != null) {
float accuracy = Float.parseFloat(accuracyProperty.getValue().toString());
int color = LocationBitmapFactory.locationColor(getApplicationContext(), location);
map.addCircle(new CircleOptions()
.center(latLng)
.radius(accuracy)
.fillColor(ColorUtils.setAlphaComponent(color, (int) (256 * .20)))
.strokeColor(ColorUtils.setAlphaComponent(color, (int) (256 * .87)))
.strokeWidth(2.0f));
double latitudePadding = (accuracy / 111325);
LatLngBounds bounds = new LatLngBounds(
new LatLng(latLng.latitude - latitudePadding, latLng.longitude),
new LatLng(latLng.latitude + latitudePadding, latLng.longitude));
int minDimension = Math.min(mapView.getWidth(), mapView.getHeight());
int padding = (int) Math.floor(minDimension / 5f);
map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, padding));
} else {
map.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 17));
}
}
}
/**
* Method returns the generated MapStyleOptions object to set to the google map.
*
* @return mapStyleOptions google map style options
*/
public MapStyleOptions getMapStyleOptions() {
return mapStyleOptions;
}
/**
* Method sets the MapStyleOptions object
*
* @param mapStyleOptions google map style options
*/
private void setMapStyleOptions(MapStyleOptions mapStyleOptions) {
this.mapStyleOptions = mapStyleOptions;
}