Rectangle 27 12

I had the same problem when I try to build a simple app, following the Android MapView tutorial.

The app showed this exception in AVD for the file file main.xml:

Failed to find style 'mapViewStyle' in current theme

At last I found that there is a mistake in file AndroidManifest.xml:

<uses-library android:name="com.google.android.maps" />
<application>
<manifest>

Sorry this is not the solution in my case.

this is not a fix, I have it as child of the application element.

java - Android Google Maps Failed to find style 'mapViewStyle' in curr...

java android google-maps
Rectangle 27 12

I had the same problem when I try to build a simple app, following the Android MapView tutorial.

The app showed this exception in AVD for the file file main.xml:

Failed to find style 'mapViewStyle' in current theme

At last I found that there is a mistake in file AndroidManifest.xml:

<uses-library android:name="com.google.android.maps" />
<application>
<manifest>

Sorry this is not the solution in my case.

this is not a fix, I have it as child of the application element.

java - Android Google Maps Failed to find style 'mapViewStyle' in curr...

java android google-maps
Rectangle 27 4

I tried to point this out to the moderators but I was ignored...

this one didn't help as well .. super useless list of links..

@ewoks +1 I totally agree - this was my attempt to get the moderators to combine these questions - they are all totally useless. Unfortunately when I flagged the question as duplicate, the moderator disagreed.

java - Android Google Maps Failed to find style 'mapViewStyle' in curr...

java android google-maps
Rectangle 27 4

I tried to point this out to the moderators but I was ignored...

this one didn't help as well .. super useless list of links..

@ewoks +1 I totally agree - this was my attempt to get the moderators to combine these questions - they are all totally useless. Unfortunately when I flagged the question as duplicate, the moderator disagreed.

java - Android Google Maps Failed to find style 'mapViewStyle' in curr...

java android google-maps
Rectangle 27 2

I was having the same problem, and it turned out the problem was I had targeted the app towards the Google 4.0 APIs, but in the Manifest file specified Android API 10 (2.3.3).

Once I changed the project's target from 4.0 to 2.3.3 (API 10), it worked better.

java - Android Google Maps Failed to find style 'mapViewStyle' in curr...

java android google-maps
Rectangle 27 2

I had the same issue when creating a Google Map view that worked well until I cleaned the project after placing a new icon.png in a drawable folder (Project >> Clean). Many times the cleaning process will install an import statement at the top program code, which overrides the R.java file in your project. The solution was to simply remove the following import statement:

after the project was saved and rebuilt without issue.

java - Android Google Maps Failed to find style 'mapViewStyle' in curr...

java android google-maps
Rectangle 27 2

My answer may be a late one, but i hope that it'll deals with the actual reason and sure it could be helpful for those who are going to search about the same problem in future.

This type of errors,

1. Android Google Maps Failed to find style 'mapViewStyle' in current theme
2. Failed to find style 'imageButtonStyle' in current theme 
3. Failed to find style 'editTextStyle' in current theme 
4. Failed to find style 'textViewStyle' in current theme

Anything from the above list it may be,

We have selected the unavailable Theme for the layout.

  • The selected theme is not available in themes.xml file.
  • The selected theme is belongs to higher version sdk, but our current target sdk is lower one.
  • when you copy the whole layout file and try to implement it in your project. a. Your may forgot to copy themes.xml file b. You may have lower target sdk, the original layout created with higher target sdk.

(Open and View the layout file in the Graphical Layout View, and look at the top Right corner. There your themes for the layout have been selected.)

  • So click the dropdown list for theme selection and choose the available themes according to your project themes and targeted sdk themes. (OR)
  • If the theme is a custom one , if you are required it , then copy the themes.xml file to your project from the source where you copied the layout xml file. (OR)
  • If the theme is sdk avail theme, if you are required it , then change your target according to your selected theme.

Hope,This might be helpful for somebody.

This is an exact copy of your answer stackoverflow.com/questions/8513278/. This issue is not related to the themes.xml, as the theme is inherited from the Maps API.

java - Android Google Maps Failed to find style 'mapViewStyle' in curr...

java android google-maps
Rectangle 27 2

I had the same issue when creating a Google Map view that worked well until I cleaned the project after placing a new icon.png in a drawable folder (Project >> Clean). Many times the cleaning process will install an import statement at the top program code, which overrides the R.java file in your project. The solution was to simply remove the following import statement:

after the project was saved and rebuilt without issue.

java - Android Google Maps Failed to find style 'mapViewStyle' in curr...

java android google-maps
Rectangle 27 2

My answer may be a late one, but i hope that it'll deals with the actual reason and sure it could be helpful for those who are going to search about the same problem in future.

This type of errors,

1. Android Google Maps Failed to find style 'mapViewStyle' in current theme
2. Failed to find style 'imageButtonStyle' in current theme 
3. Failed to find style 'editTextStyle' in current theme 
4. Failed to find style 'textViewStyle' in current theme

Anything from the above list it may be,

We have selected the unavailable Theme for the layout.

  • The selected theme is not available in themes.xml file.
  • The selected theme is belongs to higher version sdk, but our current target sdk is lower one.
  • when you copy the whole layout file and try to implement it in your project. a. Your may forgot to copy themes.xml file b. You may have lower target sdk, the original layout created with higher target sdk.

(Open and View the layout file in the Graphical Layout View, and look at the top Right corner. There your themes for the layout have been selected.)

  • So click the dropdown list for theme selection and choose the available themes according to your project themes and targeted sdk themes. (OR)
  • If the theme is a custom one , if you are required it , then copy the themes.xml file to your project from the source where you copied the layout xml file. (OR)
  • If the theme is sdk avail theme, if you are required it , then change your target according to your selected theme.

Hope,This might be helpful for somebody.

This is an exact copy of your answer stackoverflow.com/questions/8513278/. This issue is not related to the themes.xml, as the theme is inherited from the Maps API.

java - Android Google Maps Failed to find style 'mapViewStyle' in curr...

java android google-maps
Rectangle 27 2

I was having the same problem, and it turned out the problem was I had targeted the app towards the Google 4.0 APIs, but in the Manifest file specified Android API 10 (2.3.3).

Once I changed the project's target from 4.0 to 2.3.3 (API 10), it worked better.

java - Android Google Maps Failed to find style 'mapViewStyle' in curr...

java android google-maps
Rectangle 27 6

String url= 
"http://maps.googleapis.com/maps/api/directions/json?origin=" 
+ origin.latitude + "," + origin.longitude +"&destination=" 
+ destination.latitude + "," + destination.longitude + "&sensor=false";

To fetch the data with androidhttpclient, do something like this:

HttpResponse response;
HttpGet request;
AndroidHttpClient client = AndroidHttpClient.newInstance("somename");

request = new HttpGet(url);
response = client.execute(request);

InputStream source = response.getEntity().getContent();
String returnValue = buildStringIOutils(source);

return returnValue;
private String buildStringIOutils(InputStream is) {
    try {
        return IOUtils.toString(is, "UTF-8");
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}

You can then extract the actual polyline from the JSON-response with something like this:

JSONObject result = new JSONObject(returnValue);
JSONArray routes = result.getJSONArray("routes");

                    long distanceForSegment = routes.getJSONObject(0).getJSONArray("legs").getJSONObject(0).getJSONObject("distance").getInt("value");

                    JSONArray steps = routes.getJSONObject(0).getJSONArray("legs")
                            .getJSONObject(0).getJSONArray("steps");

                    List<LatLng> lines = new ArrayList<LatLng>();

                    for(int i=0; i < steps.length(); i++) {
                        String polyline = steps.getJSONObject(i).getJSONObject("polyline").getString("points");

                        for(LatLng p : decodePolyline(polyline)) {
                            lines.add(p);
                        }
                    }

where the method decodePolyline is this:

/** POLYLINE DECODER - http://jeffreysambells.com/2010/05/27/decoding-polylines-from-google-maps-direction-api-with-java **/
    private List<LatLng> decodePolyline(String encoded) {

        List<LatLng> poly = new ArrayList<LatLng>();

        int index = 0, len = encoded.length();
        int lat = 0, lng = 0;

        while (index < len) {
            int b, shift = 0, result = 0;
            do {
                b = encoded.charAt(index++) - 63;
                result |= (b & 0x1f) << shift;
                shift += 5;
            } while (b >= 0x20);
            int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
            lat += dlat;

            shift = 0;
            result = 0;
            do {
                b = encoded.charAt(index++) - 63;
                result |= (b & 0x1f) << shift;
                shift += 5;
            } while (b >= 0x20);
            int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
            lng += dlng;

            LatLng p = new LatLng((double) lat / 1E5, (double) lng / 1E5);
            poly.add(p);
        }

        return poly;
    }

You can then add the polyline to the map with this:

Polyline polylineToAdd = mMap.addPolyline(new PolylineOptions().addAll(lines).width(3).color(Color.RED));

driving (default) indicates standard driving directions using the road network.

Edit: About the "I would also like to get traffic information such as busy routes, congestion, etc." I have not looked into this, but my code should get you started pretty good.

Edit2: Found this in the google directions api: "For Driving Directions: Maps for Business customers can specify the departure_time to receive trip duration considering current traffic conditions. The departure_time must be set to within a few minutes of the current time."

java - Find route with Androids Google Maps API - Stack Overflow

java android google-maps google-maps-api-3 google-maps-api-2
Rectangle 27 3

Android Google Maps Routing example code using Wrapper library

compile 'com.github.jd-alexander:library:1.1.0'
import android.Manifest;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.directions.route.Route;
import com.directions.route.RouteException;
import com.directions.route.Routing;
import com.directions.route.RoutingListener;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
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 com.google.android.gms.maps.model.Polyline;
import com.google.android.gms.maps.model.PolylineOptions;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class MainActivity extends FragmentActivity implements OnMapReadyCallback, LocationListener, GoogleMap.OnMarkerClickListener, RoutingListener {

    private GoogleMap mMap = null;
    private LocationManager locationManager = null;
    private FloatingActionButton fab = null;
    private TextView txtDistance, txtTime;

    //Global UI Map markers
    private Marker currentMarker = null;
    private Marker destMarker = null;
    private LatLng currentLatLng = null;
    private Polyline line = null;

    //Global flags
    private boolean firstRefresh = true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map);
        Constants.POINT_DEST = new LatLng(18.758663, 73.382025);        //Lonavala destination.
        //Load the map fragment on UI
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
        txtDistance = (TextView)findViewById(R.id.txt_distance);
        txtTime = (TextView)findViewById(R.id.txt_time);
        fab = (FloatingActionButton)findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MainActivity.this.getRoutingPath();
                Snackbar.make(v, "Fetching Route", Snackbar.LENGTH_SHORT).show();
            }
        });

    }

    @Override
    protected void onResume() {
        super.onResume();
        firstRefresh = true;
        //Ensure the GPS is ON and location permission enabled for the application.
        locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
        if (!PermissionCheck.getInstance().checkGPSPermission(this, locationManager)) {
            //GPS not enabled for the application.
        } else if (!PermissionCheck.getInstance().checkLocationPermission(this)) {
            //Location permission not given.
        } else {
            Toast.makeText(MainActivity.this, "Fetching Location", Toast.LENGTH_SHORT).show();
            try {
                locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
                locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000, 0, this);
            } catch(Exception e)
            {
                Toast.makeText(MainActivity.this, "ERROR: Cannot start location listener", Toast.LENGTH_SHORT).show();
            }
        }
    }

    @Override
    protected void onPause() {
        if (locationManager != null) {
            //Check needed in case of  API level 23.

            if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            }
            try {
                locationManager.removeUpdates(this);
            } catch (Exception e) {
            }
        }
        locationManager = null;
        super.onPause();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    public void onMapReady(GoogleMap googleMap)
    {
        mMap = googleMap;
        //mMap.getUiSettings().setZoomControlsEnabled(true);
        mMap.getUiSettings().setCompassEnabled(true);
        mMap.getUiSettings().setAllGesturesEnabled(true);
        mMap.setOnMarkerClickListener(this);
    }

    /**
     * @desc LocationListener Interface Methods implemented.
     */

    @Override
    public void onLocationChanged(Location location)
    {
        double lat = location.getLatitude();
        double lng = location.getLongitude();
        currentLatLng = new LatLng(lat, lng);
        if(firstRefresh)
        {
            //Add Start Marker.
            currentMarker = mMap.addMarker(new MarkerOptions().position(currentLatLng).title("Current Position"));//.icon(BitmapDescriptorFactory.fromResource(R.drawable.location)));
            firstRefresh = false;
            destMarker = mMap.addMarker(new MarkerOptions().position(Constants.POINT_DEST).title("Destination"));//.icon(BitmapDescriptorFactory.fromResource(R.drawable.location)));
            mMap.moveCamera(CameraUpdateFactory.newLatLng(Constants.POINT_DEST));
            mMap.animateCamera(CameraUpdateFactory.zoomTo(15));
            getRoutingPath();
        }
        else
        {
            currentMarker.setPosition(currentLatLng);
        }
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {}

    @Override
    public void onProviderEnabled(String provider) {}

    @Override
    public void onProviderDisabled(String provider) {}

    /**
     * @desc MapMarker Interface Methods Implemented.
     */

    @Override
    public boolean onMarkerClick(Marker marker)
    {
        if(marker.getTitle().contains("Destination"))
        {
            //Do some task on dest pin click
        }
        else if(marker.getTitle().contains("Current"))
        {
            //Do some task on current pin click
        }
        return false;
    }

    /**
     *@desc Routing Listener interface methods implemented.
     **/
    @Override
    public void onRoutingFailure(RouteException e)
    {
        Toast.makeText(MainActivity.this, "Routing Failed", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onRoutingStart() { }

    @Override
    public void onRoutingSuccess(ArrayList<Route> list, int i)
    {
        try
        {
            //Get all points and plot the polyLine route.
            List<LatLng> listPoints = list.get(0).getPoints();
            PolylineOptions options = new PolylineOptions().width(5).color(Color.BLUE).geodesic(true);
            Iterator<LatLng> iterator = listPoints.iterator();
            while(iterator.hasNext())
            {
                LatLng data = iterator.next();
                options.add(data);
            }

            //If line not null then remove old polyline routing.
            if(line != null)
            {
                line.remove();
            }
            line = mMap.addPolyline(options);

            //Show distance and duration.
            txtDistance.setText("Distance: " + list.get(0).getDistanceText());
            txtTime.setText("Duration: " + list.get(0).getDurationText());

            //Focus on map bounds
            mMap.moveCamera(CameraUpdateFactory.newLatLng(list.get(0).getLatLgnBounds().getCenter()));
            LatLngBounds.Builder builder = new LatLngBounds.Builder();
            builder.include(currentLatLng);
            builder.include(Constants.POINT_DEST);
            LatLngBounds bounds = builder.build();
            mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 50));
        }
        catch (Exception e) 
        {
            Toast.makeText(MainActivity.this, "EXCEPTION: Cannot parse routing response", Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onRoutingCancelled() 
    {
        Toast.makeText(MainActivity.this, "Routing Cancelled", Toast.LENGTH_SHORT).show();
    }

    /**
     * @method getRoutingPath
     * @desc Method to draw the google routed path.
     */
    private void getRoutingPath()
    {
        try
        {
            //Do Routing
            Routing routing = new Routing.Builder()
                    .travelMode(Routing.TravelMode.DRIVING)
                    .withListener(this)
                    .waypoints(currentLatLng, Constants.POINT_DEST)
                    .build();
            routing.execute();
        }
        catch (Exception e)
        {
            Toast.makeText(MainActivity.this, "Unable to Route", Toast.LENGTH_SHORT).show();
        }
    }

}
/**
 * @class Constants
 * @desc Constant class for holding values at runtime.
 */
public class Constants
{

    //Map LatLong points
    public static LatLng POINT_DEST = null;

}
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/viewA"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="0.1"
        android:orientation="horizontal">

        <fragment
            android:id="@+id/map"
            android:name="com.google.android.gms.maps.SupportMapFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context="com.packagename.MainActivity" />


    </LinearLayout>

    <LinearLayout
        android:id="@+id/viewB"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="0.9"
        android:gravity="center|left"
        android:paddingLeft="20dp"
        android:background="#FFFFFF"
        android:orientation="vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="16dp"
            android:text="Distance ?"
            android:paddingTop="3dp"
            android:paddingLeft="3dp"
            android:paddingBottom="3dp"
            android:id="@+id/txt_distance" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="17dp"
            android:paddingLeft="3dp"
            android:text="Duration ?"
            android:id="@+id/txt_time" />

    </LinearLayout>

</LinearLayout>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="16dp"
    android:clickable="true"
    android:src="@android:drawable/ic_dialog_map"
    app:layout_anchor="@id/viewA"
    app:layout_anchorGravity="bottom|right|end"/>

</android.support.design.widget.CoordinatorLayout>

java - Find route with Androids Google Maps API - Stack Overflow

java android google-maps google-maps-api-3 google-maps-api-2
Rectangle 27 3

Try the Google Directions API. It's a web service, which gives turn-by-turn guides in JSON-Format with all information to get from point A to B by car, transit or your feet.

To code that follow the link in the comment of Stochastically.

In the introduction to the API, it states "This service is generally designed for calculating directions for static (known in advance) addresses for placement of application content on a map; this service is not designed to respond in real time to user input, for example. For dynamic directions calculations (for example, within a user interface element), consult the documentation for the JavaScript API V3 Directions Service."

Yes, the point is that the API isn't designed for multiple real-time calls. Just call the API once, extract the information from JSON and loop through it till you have arrived. How I said the API gives the information, but the logic to handle that information has to be implemented.

java - Find route with Androids Google Maps API - Stack Overflow

java android google-maps google-maps-api-3 google-maps-api-2
Rectangle 27 3

If it fails on myLocation.getLatitude(); as you mentioned in the comment then it means that locationManager.getLastKnownLocation(provider); doesn't return a last known location because it doesn't have one so it return null and this is the reason you have a NullPointerExeception error. you need to implement a LocationListener in this case and to run this method after you have received at least one location update.

To implement LocationListener you can check this example:

I guess that this reading material could be really handy as well for you:

It works like a charm. Thanks Dude.

java - Can't find user location Google Maps Api v2 - Stack Overflow

java android google-maps latitude-longitude google-maps-api-2
Rectangle 27 11

Because there were like 4 or 5 question about the same topic, BUT with DIFFERENT requirements, and I tried to answer all of them, but a non-polite admin deleted/closed them, making me create a ticket for each one and changing them to avoid "copy paste" I will let you a link to the full answer in where you can find all the explanation about how to get full behavior like Google Maps.

With support library 23.x.x+ you can do it modifying the default BottomSheetBehavior, adding one more stat with following steps:

CoordinatorLayout.Behavior<V>
BottomSheetBehavior
  • Modify the method clampViewPositionVertical with the following code:
  • Add a new state: public static final int STATE_ANCHOR_POINT = X;
onLayoutChild
onStopNestedScroll
BottomSheetBehavior<V> from(V view)
setState

I'm going to add those modified methods and a link to the example project.

I've tested the github repo now, and it seems nice. But the upper blue area looks partial sometimes. Also, I can't find out where to handle views that need to move as you drag the bottom sheet. In the repo I've made (here: github.com/AndroidDeveloperLB/ThreePhasesBottomSheet) , the image fades, and the small image moves from one place to another, including changing its size. I'd like to know where to add the handling of those.

Hi there, I have a local version with parallax image but it is not working well yet (I can push it if u wanna look it). You can add any view inside the CoordinatorLayout in activity_main.xml. I guess you have good experience with coordinator layout, otherwise take a look at this link that I found

I'm going to see how did you got toolbar behavior and will use it on mine :D. By the way there is a little behavior that I could only mimic if I use support library 23.2: in google maps if you drag the image that below the toolbar it will move the bottomsheet, but if you upgrade to 23.4 or minSdkVersion 14+ you will lose this behavior o_O'

@androiddeveloper I got it! now its working with image parallax effect and toolbars animations...I'm only missing the color that takes the toolbar when you keep sliding up :D

@MiguelHincapieC Hi, I want to only display main toolbar and i removed merged appbar layout but on bottom sheet expand time status bar not displaying and parallex image end to status bar position and i want to parallex image sticky below main toolbar. can you explain how can i do it

android - How to mimic Google Maps' bottom-sheet 3 phases behavior? - ...

android material-design android-coordinatorlayout android-design-library collapsingtoolbarlayout
Rectangle 27 4

UPDATE Link to the full answer in where you can find all the explanation about how to get full behaviors like Google Maps.

Helping you with what you want

what I wanted, which is the 3-phases I've done before

Using Support Library 23.x+ you can do it modifying default BottomSheetBehavior adding one more stat with following steps:

CoordinatorLayout.Behavior<V>
BottomSheetBehavior
clampViewPositionVertical

Add a new state

onLayoutChild
onStopNestedScroll
BottomSheetBehavior<V> from(V view)
setState

You can use setBottomSheetCallback like you do in original BottomSheetBehavior The XML (without anything about parallax image like google maps) looks like:

<CoordinatorLayout>

    <FrameLayout/>

    <AppBarLayout>
        <CollapsingToolbarLayout>
            <Toolbar/>
        </CollapsingToolbarLayout >
    </AppBarLayout >

    <NestedScrollView>
        <LinearLayout/>
    </NestedScrollView>

</CoordinatorLayout >

I'm going to add a link to the example project where you can find what you are looking for

android - How to handle issues of the new bottom sheet of the support/...

android android-support-library android-design-library bottom-sheet
Rectangle 27 6

BIG UPDATE Because there were like 4 or 5 question about the same topic BUT with DIFFERENTS requeriments and I tried to answer all of them a non polite admin deleted/close them making me create a ticket for each one and changing them to avoid "copy paste" I will let you a link to the full answer in where you can find all the explanation about how to get full behavior like Google Maps.

How could I use BottomSheetBehavior and get this additional anchored state?

You can do it modifying default BottomSheetBehavior adding one more stat with following steps:

CoordinatorLayout.Behavior<V>
BottomSheetBehavior

Modify the method clampViewPositionVertical with the following code:

@Override public int clampViewPositionVertical(View child, int top, int dy) { return constrain(top, mMinOffset, mHideable ? mParentHeight : mMaxOffset); } int constrain(int amount, int low, int high) { return amount < low ? low : (amount > high ? high : amount); }

Add a new state

onLayoutChild
onStopNestedScroll
BottomSheetBehavior<V> from(V view)
setState

I'm going to add those modified methods and a link to the example project

public boolean onLayoutChild(CoordinatorLayout parent, V child, int layoutDirection) {
    // First let the parent lay it out
    if (mState != STATE_DRAGGING && mState != STATE_SETTLING) {
        if (ViewCompat.getFitsSystemWindows(parent) &&
                !ViewCompat.getFitsSystemWindows(child)) {
            ViewCompat.setFitsSystemWindows(child, true);
        }
        parent.onLayoutChild(child, layoutDirection);
    }
    // Offset the bottom sheet
    mParentHeight = parent.getHeight();
    mMinOffset = Math.max(0, mParentHeight - child.getHeight());
    mMaxOffset = Math.max(mParentHeight - mPeekHeight, mMinOffset);

    //if (mState == STATE_EXPANDED) {
    //    ViewCompat.offsetTopAndBottom(child, mMinOffset);
    //} else if (mHideable && mState == STATE_HIDDEN...
    if (mState == STATE_ANCHOR_POINT) {
        ViewCompat.offsetTopAndBottom(child, mAnchorPoint);
    } else if (mState == STATE_EXPANDED) {
        ViewCompat.offsetTopAndBottom(child, mMinOffset);
    } else if (mHideable && mState == STATE_HIDDEN) {
        ViewCompat.offsetTopAndBottom(child, mParentHeight);
    } else if (mState == STATE_COLLAPSED) {
        ViewCompat.offsetTopAndBottom(child, mMaxOffset);
    }
    if (mViewDragHelper == null) {
        mViewDragHelper = ViewDragHelper.create(parent, mDragCallback);
    }
    mViewRef = new WeakReference<>(child);
    mNestedScrollingChildRef = new WeakReference<>(findScrollingChild(child));
    return true;
}


public void onStopNestedScroll(CoordinatorLayout coordinatorLayout, V child, View target) {
    if (child.getTop() == mMinOffset) {
        setStateInternal(STATE_EXPANDED);
        return;
    }
    if (target != mNestedScrollingChildRef.get() || !mNestedScrolled) {
        return;
    }
    int top;
    int targetState;
    if (mLastNestedScrollDy > 0) {
        //top = mMinOffset;
        //targetState = STATE_EXPANDED;
        int currentTop = child.getTop();
        if (currentTop > mAnchorPoint) {
            top = mAnchorPoint;
            targetState = STATE_ANCHOR_POINT;
        }
        else {
            top = mMinOffset;
            targetState = STATE_EXPANDED;
        }
    } else if (mHideable && shouldHide(child, getYVelocity())) {
        top = mParentHeight;
        targetState = STATE_HIDDEN;
    } else if (mLastNestedScrollDy == 0) {
        int currentTop = child.getTop();
        if (Math.abs(currentTop - mMinOffset) < Math.abs(currentTop - mMaxOffset)) {
            top = mMinOffset;
            targetState = STATE_EXPANDED;
        } else {
            top = mMaxOffset;
            targetState = STATE_COLLAPSED;
        }
    } else {
        //top = mMaxOffset;
        //targetState = STATE_COLLAPSED;
        int currentTop = child.getTop();
        if (currentTop > mAnchorPoint) {
            top = mMaxOffset;
            targetState = STATE_COLLAPSED;
        }
        else {
            top = mAnchorPoint;
            targetState = STATE_ANCHOR_POINT;
        }
    }
    if (mViewDragHelper.smoothSlideViewTo(child, child.getLeft(), top)) {
        setStateInternal(STATE_SETTLING);
        ViewCompat.postOnAnimation(child, new SettleRunnable(child, targetState));
    } else {
        setStateInternal(targetState);
    }
    mNestedScrolled = false;
}

public final void setState(@State int state) {
    if (state == mState) {
        return;
    }
    if (mViewRef == null) {
        // The view is not laid out yet; modify mState and let onLayoutChild handle it later
        /**
         * New behavior (added: state == STATE_ANCHOR_POINT ||)
         */
        if (state == STATE_COLLAPSED || state == STATE_EXPANDED ||
                state == STATE_ANCHOR_POINT ||
                (mHideable && state == STATE_HIDDEN)) {
            mState = state;
        }
        return;
    }
    V child = mViewRef.get();
    if (child == null) {
        return;
    }
    int top;
    if (state == STATE_COLLAPSED) {
        top = mMaxOffset;
    } else if (state == STATE_ANCHOR_POINT) {
        top = mAnchorPoint;
    } else if (state == STATE_EXPANDED) {
        top = mMinOffset;
    } else if (mHideable && state == STATE_HIDDEN) {
        top = mParentHeight;
    } else {
        throw new IllegalArgumentException("Illegal state argument: " + state);
    }
    setStateInternal(STATE_SETTLING);
    if (mViewDragHelper.smoothSlideViewTo(child, child.getLeft(), top)) {
        ViewCompat.postOnAnimation(child, new SettleRunnable(child, state));
    }
}


public static <V extends View> BottomSheetBehaviorGoogleMapsLike<V> from(V view) {
    ViewGroup.LayoutParams params = view.getLayoutParams();
    if (!(params instanceof CoordinatorLayout.LayoutParams)) {
        throw new IllegalArgumentException("The view is not a child of CoordinatorLayout");
    }
    CoordinatorLayout.Behavior behavior = ((CoordinatorLayout.LayoutParams) params)
            .getBehavior();
    if (!(behavior instanceof BottomSheetBehaviorGoogleMapsLike)) {
        throw new IllegalArgumentException(
                "The view is not associated with BottomSheetBehaviorGoogleMapsLike");
    }
    return (BottomSheetBehaviorGoogleMapsLike<V>) behavior;
}
behavior.setBottomSheetCallback(new BottomSheetBehaviorGoogleMapsLike.BottomSheetCallback() {....

Thanks, I'll look into this when I get to implementing that final state. It'd be nice to not have to copy/paste code. Would be better if it was possible to subclass in some way, but probably needs code not visible in subclass.

Yeah I tried to subclass but was a pain in the %$#. Now I'm working in parallax image effect like google maps.

@JeffLockhart I got it! now its working with image parallax effect and toolbars animations...I'm only missing the color that takes the toolbar when you keep sliding up :D

yes, thank you. We are still working on finalizing the design for this behavior, after which I'll be able to finish implementing it in code. This information is helpful, thank you.

Android Support BottomSheetBehavior additional anchored state - Stack ...

android android-support-library android-design-library bottom-sheet
Rectangle 27 15

This is the second easy approach to the problem: we will call the non-public method namedGroups() in Pattern class to obtain a Map<String, Integer> that maps group names to the group numbers via Java Reflection API. The advantage of this approach is that we don't need a string that contains a match to the regex to find the exact named groups.

However, please take note of the drawbacks

  • This approach may not apply if the code is run in a system with security restrictions to deny any attempts to gain access to non-public methods (no modifier, protected and private methods).
  • The code is only applicable to JRE from Oracle or OpenJDK.
  • The code may also break in future releases, since we are calling a non-public method.
  • There may also be performance hit from calling function via reflection. (In this case, the performance hit mainly comes from the reflection overhead, since there is not much going on in namedGroups() method). I do not know how the performance hit affects overall performance, so please do measurement on your system.
import java.util.Collections;
import java.util.Map;
import java.util.Scanner;
import java.util.regex.Pattern;

import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;

class RegexTester {
  public static void main(String args[]) {
    Scanner scanner = new Scanner(System.in);

    String regex = scanner.nextLine();
    // String regex = "(?<group>[a-z]*)[trick(?<nothing>ha)]\\Q(?<quoted>Q+E+)\\E(.*)(?<Another6group>\\w+)";
    Pattern p = Pattern.compile(regex);

    Map<String, Integer> namedGroups = null;
    try {
      namedGroups = getNamedGroups(p);
    } catch (Exception e) {
      // Just an example here. You need to handle the Exception properly
      e.printStackTrace();
    }

    System.out.println(namedGroups);
  }


  @SuppressWarnings("unchecked")
  private static Map<String, Integer> getNamedGroups(Pattern regex)
      throws NoSuchMethodException, SecurityException,
             IllegalAccessException, IllegalArgumentException,
             InvocationTargetException {

    Method namedGroupsMethod = Pattern.class.getDeclaredMethod("namedGroups");
    namedGroupsMethod.setAccessible(true);

    Map<String, Integer> namedGroups = null;
    namedGroups = (Map<String, Integer>) namedGroupsMethod.invoke(regex);

    if (namedGroups == null) {
      throw new InternalError();
    }

    return Collections.unmodifiableMap(namedGroups);
  }
}

Get group names in java regex - Stack Overflow

java regex
Rectangle 27 4

If you are lucky and you are using mysql or postgresql which both are spatial enabled databases you can execute spatial queries against them.For mysql there are spatial extensions and for postgresql there is postgis. If you decide to go manual please take look at this question for heads up.Also i don't understand how the google places api can help you since you are looking your data within a radius and not google places. Cheers

google maps - How to find distance between two addresses? (Java server...

google-maps geolocation distance street-address
Rectangle 27 4

if you're using SQL (you didn't say)... I think I copied this from the NerdDinner project:

ALTER FUNCTION [dbo].[DistanceBetween] (@Lat1 as real,
                @Long1 as real, @Lat2 as real, @Long2 as real)
RETURNS real
AS
BEGIN

DECLARE @dLat1InRad as float(53);
SET @dLat1InRad = @Lat1 * (PI()/180.0);
DECLARE @dLong1InRad as float(53);
SET @dLong1InRad = @Long1 * (PI()/180.0);
DECLARE @dLat2InRad as float(53);
SET @dLat2InRad = @Lat2 * (PI()/180.0);
DECLARE @dLong2InRad as float(53);
SET @dLong2InRad = @Long2 * (PI()/180.0);

DECLARE @dLongitude as float(53);
SET @dLongitude = @dLong2InRad - @dLong1InRad;
DECLARE @dLatitude as float(53);
SET @dLatitude = @dLat2InRad - @dLat1InRad;
/* Intermediate result a. */
DECLARE @a as float(53);
SET @a = SQUARE (SIN (@dLatitude / 2.0)) + COS (@dLat1InRad)
                 * COS (@dLat2InRad)
                 * SQUARE(SIN (@dLongitude / 2.0));
/* Intermediate result c (great circle distance in Radians). */
DECLARE @c as real;
SET @c = 2.0 * ATN2 (SQRT (@a), SQRT (1.0 - @a));
DECLARE @kEarthRadius as real;
/* SET kEarthRadius = 3956.0 miles */
SET @kEarthRadius = 6376.5;        /* kms */

DECLARE @dDistance as real;
SET @dDistance = @kEarthRadius * @c;
return (@dDistance);
END


ALTER FUNCTION [dbo].[NearestPeople]
    (
    @lat real,
    @long real,
    @maxdist real
    )
RETURNS  TABLE
AS
    RETURN
    SELECT     Person.ID
    FROM       Person
    WHERE dbo.DistanceBetween(@lat, @long, Latitude, Longitude) < @maxdist

I then use these SQL functions from the server like this in C#:

public IQueryable<Person> FindNearbyPeople(float latitude, float longitude, float maxdistance)
{
    var people = from person in FindAllPeople()
                 join i in db.NearestPeople(latitude, longitude, maxdistance)
                 on person.ID equals i.ID
                 select person;

    return people;
}

that tells me who (in this case, people) is close to me within a maximum distance.

this is the free version. I think SQL Server 2008 can perform this with a Geographic package

google maps - How to find distance between two addresses? (Java server...

google-maps geolocation distance street-address