google map polyline is not working on android version 5.0(lollipop)

前端 未结 2 1539
感动是毒
感动是毒 2020-12-22 05:28

i am trying to draw polyline for googlemap, it is working fine upto android version 4.4(kitkat) but it is not working in android 5.0(lollipop). what to do for working in lol

相关标签:
2条回答
  • 2020-12-22 06:03

    Try the modified codes for your onPostExecute:

    @Override
    protected void onPostExecute(List<List<HashMap<String, String>>> result) {
            ArrayList<LatLng> points = null;
            //PolylineOptions lineOptions = null;
    
            //MarkerOptions markerOptions = new MarkerOptions();
    
            points = new ArrayList<LatLng>();
    
            // Traversing through all the routes
            for(int i=0;i<result.size();i++){
                //points = new ArrayList<LatLng>();
                //lineOptions = new PolylineOptions();              
    
                // Fetching i-th route
                List<HashMap<String, String>> path = result.get(i);
    
                // Fetching all the points in i-th route
                for(int j=0;j<path.size();j++){
                    HashMap<String,String> point = path.get(j);                 
    
                    double lat = Double.parseDouble(point.get("lat"));
                    double lng = Double.parseDouble(point.get("lng"));
                    LatLng position = new LatLng(lat, lng); 
    
                    points.add(position);                       
                }
    
                // Adding all the points in the route to LineOptions
                //lineOptions.addAll(points);
                //lineOptions.width(4);
                //lineOptions.color(Color.BLUE);
    
            }
    
            // Drawing polyline in the Google Map for the i-th route
            //map.addPolyline(lineOptions); 
    
            lineOptions.addAll(points);
            lineOptions.width(4);
            lineOptions.color(Color.BLUE); 
            line = map.addPolyline(lineOptions);
        }           
    

    I moved your list points instance before for loop, and also lineOptions after for loop.

    Hope this help.

    0 讨论(0)
  • 2020-12-22 06:03

    Now Again Google has released a new API but they haven't updated the documentation properly.To connect to the API, you need to create an instance of the Google Play services API client.

     mGoogleApiClient = new GoogleApiClient.Builder(this)
        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this)
        .addApi(LocationServices.API)
        .build();
    

    Once you have connected to Google Play services and the location services API, you can get the last known location of a user's device. When your app is connected to these you can use the fused location provider's getLastLocation() method to retrieve the device location. To do this you have to implements this interfaces in your Class/Activity

    implements
        ConnectionCallbacks, OnConnectionFailedListener
    

    Then you can found this implemented methods

    @Override
        public void onConnected(Bundle bundle) {
    mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
                    mGoogleApiClient);
            if (mLastLocation != null) {
                mLatitudeText.setText(String.valueOf(mLastLocation.getLatitude()));
                mLongitudeText.setText(String.valueOf(mLastLocation.getLongitude()));
            }
        }
    
        @Override
        public void onConnectionSuspended(int i) {
    
        }
    
        @Override
        public void onConnectionFailed(ConnectionResult connectionResult) {
    
        }
    

    Here is my complete code into this thread . Documentation is here

    0 讨论(0)
提交回复
热议问题