谷歌地图折线不适用于Android 5.0版(棒棒糖)

谷歌地图折线不适用于Android 5.0版(棒棒糖),第1张

概述我正在尝试为googlemap绘制折线,它工作正常到Android版本4.4(kitkat),但它不能在android5.0(棒棒糖).怎么做在棒棒糖工作也.你能不能帮我解决这个问题这是我的谷歌地图代码publicclassMapLocationextendsFragmentActivityimplementsOnMarkerClickListener{GoogleMa

我正在尝试为Googlemap绘制折线,它工作正常到Android版本4.4(kitkat),但它不能在androID 5.0(棒棒糖).怎么做在棒棒糖工作也.你能不能帮我解决这个问题这是我的谷歌地图代码

public class MapLocation extends FragmentActivity implements OnMarkerClickListener {    GoogleMap map;    ArrayList<LatLng> markerPoints;    LatLng origin,dest1,dest2,dest3;        Marker marker1,marker2,marker3;    polylineoptions lineOptions = new polylineoptions();    polyline line ;    int pos;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        //this.requestwindowFeature(Window.FEATURE_NO_Title);        setContentVIEw(R.layout.gmap_direction);        markerPoints = new ArrayList<LatLng>();        // Getting reference to SupportMapFragment of the activity_main        SupportMapFragment fm = (SupportMapFragment)getSupportFragmentManager().findFragmentByID(R.ID.map);        // Getting Map for the SupportMapFragment        map = fm.getMap();              if(map!=null){            // Enable MyLocation button in the Map            map.setMyLocationEnabled(true);                 // Getting LocationManager object from System Service LOCATION_SERVICE            LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);            // Creating a criteria object to retrIEve provIDer            Criteria criteria = new Criteria();            // Getting the name of the best provIDer            String provIDer = locationManager.getBestProvIDer(criteria, true);            // Getting Current Location            Location location = locationManager.getLastKNownLocation(provIDer);            pos = getIntent().getIntExtra("pos",0);             try{            switch (pos) {               case 1:                   dest2 = new LatLng(18.545981, 73.902132);                   marker2 = map.addMarker(new MarkerOptions().position(dest2).Title("Vivero International Preschool").snippet("PUNE,KALYANINAGAR").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));                   break;               case 2:                   dest2 = new LatLng(17.429122, 78.412745);                   marker2 =  map.addMarker(new MarkerOptions().position(dest2).Title("Vivero International Preschool").snippet("Jubilee Hills").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));                   break;               case 3:                   dest2 =  new LatLng(19.115177, 72.909486);                   marker2 = map.addMarker(new MarkerOptions().position(dest2).Title("Vivero International Preschool").snippet("MUMBAI, POWAI").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));                   break;               case 4:                   dest2 = new LatLng(18.545981, 73.902132);                   marker2 =  map.addMarker(new MarkerOptions().position(dest2).Title("Vivero International Preschool").snippet("PUNE,MAGARPATTA").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));                   break;               case 5:                   dest2 = new LatLng(12.924438, 77.631537);                   marker2 =  map.addMarker(new MarkerOptions().position(dest2).Title("Vivero International Preschool").snippet("Koramangala").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));                   break;               case 6:                   dest2 =  new LatLng(12.9044019,77.6690773);                   marker2 = map.addMarker(new MarkerOptions().position(dest2).Title("Vivero International Preschool").snippet("Sarjapur").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));                   break;               case 7:                   dest2 = new LatLng(12.972442, 77.639195);                   marker2 =  map.addMarker(new MarkerOptions().position(dest2).Title("Vivero International Preschool").snippet("Indiranagar").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));                   break;               case 8:                   dest2 = new LatLng(12.968719, 77.747883);                   marker2 =  map.addMarker(new MarkerOptions().position(dest2).Title("Vivero International Preschool").snippet("WhitefIEld").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));                   break;                   //  dest1 = new LatLng(19.115177, 72.909486);            }            // Showing the current location in Google Map            map.moveCamera(CameraUpdateFactory.newLatLng(dest2));            // Zoom in the Google Map            map.animateCamera(CameraUpdateFactory.zoomTo(15));                 marker2.showInfoWindow();               if(location!=null){                onLocationChanged(location);            String url = getDirectionsUrl(origin, dest2);                           DownloadTask downloadTask = new DownloadTask();            // Start downloading Json data from Google Directions API            downloadTask.execute(url);            }            }            catch(Exception e){            }        }           }    /** A class to parse the Google Places in JsON format */    private class ParserTask extends AsyncTask<String, Integer, List<List<HashMap<String,String>>> >{        // Parsing the data in non-ui thread                @OverrIDe        protected List<List<HashMap<String, String>>> doInBackground(String... JsonData) {            JsONObject jObject;             List<List<HashMap<String, String>>> routes = null;                                 try{                jObject = new JsONObject(JsonData[0]);                DirectionsJsONParser parser = new DirectionsJsONParser();                // Starts parsing data                routes = parser.parse(jObject);                }catch(Exception e){                e.printstacktrace();            }            return routes;        }        // Executes in UI thread, after the parsing process        @OverrIDe        protected voID onPostExecute(List<List<HashMap<String, String>>> result) {            ArrayList<LatLng> points = null;            //polylineoptions lineOptions = null;            MarkerOptions markerOptions = new MarkerOptions();            // 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);             line = map.addpolyline(lineOptions);        }               }} 

解决方法:

尝试修改onPostExecute的代码:

@OverrIDeprotected 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);    }           

我在for循环之前移动了列表点实例,在for循环之后移动了lineOptions.

希望这有帮助.

总结

以上是内存溢出为你收集整理的谷歌地图折线不适用于Android 5.0版(棒棒糖)全部内容,希望文章能够帮你解决谷歌地图折线不适用于Android 5.0版(棒棒糖)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1099245.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存