Unable to see multiple marker on google Map

后端 未结 3 1897
灰色年华
灰色年华 2021-01-21 04:53

I want to show multiple markers on a google map. My latlng coordinates are fetched from a Parse database but I am not able see marker. My second problem is that I

相关标签:
3条回答
  • 2021-01-21 05:46

    Try this

    //  Create lat long points
    Latlng[] point_new = new LatLng[8];
                    point_new[0] = new LatLng(31.5301843, 74.3207487);
                    point_new[1] = new LatLng(31.5214693,74.3236027);
                    point_new[2] = new LatLng(31.5194393, 74.3257327);
                    point_new[3] = new LatLng(31.4942166, 74.3004533);
                    point_new[4] = new LatLng(31.4864646, 74.2911203);
                    point_new[5] = new LatLng(31.4803596, 74.2787933);
                    point_new[6] = new LatLng(31.4764716, 74.2638203);
                    point_new[7] = new LatLng(31.4775236, 74.2628873);
    //  Add markers 
    
     for (int i = 0; i < point_new.length; i++) {
                        MarkerOptions markerOptions = new MarkerOptions()
                                .position(point_new[i]);
                        marker = mMap.addMarker(markerOptions);
                        marker.setTitle("Points");
                        marker.setSnippet("Distance = 9.6 km, Time = 20 minute/s");
                        marker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.p));
    }
    

    // Set camera to last point with Zoom level 9

    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(point_new[7], 9));
    
    0 讨论(0)
  • 2021-01-21 05:55

    it might due to unreachability of googleMap object in onPostExecute() . Please ensure that googleMap is declared globally.

    if possible please paste whole code for better evaluation

    0 讨论(0)
  • 2021-01-21 05:57

    I see a few problems here.

    As @Raghunandan mentioned, you cannot update the UI from doInBackground() so you cannot add markers from there. You can however, make your MarkerOptions objects here, and then attach them to the GoogleMap in your postExecute/or in the Activity that hosts the Google Maps.

    In your onPostExecute(), you have not set any Title, or Snippet to your markers. Whenever you are creating your marker, make sure to set your title. Then when the user clicks on the marker, the default behavior shows your rest name as a title. Code will be something like this(as also mentioned by @Inzimam Tariq IT :

    MarkerOptions markerOptions = new MarkerOptions();
                    markerOptions.position(res)
                    .setTitle(restaurantName)
                    .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
                    googleMap.addMarker(markerOptions);
    
    0 讨论(0)
提交回复
热议问题