简体   繁体   中英

Markers not shown at google map

I have following code in which I want to show marker, the latitude and longitude of place is stored in array but I my markers are not showing on map I don't know why :| I printed these values for checking values are correct but marrker not shown

if (f[l].equals(restTypefrag[n])) {
                    Log.i("okkk", "lattitude " + la[n] + "longtitude " + lo[n] +"name " + namefrag[n]);
                  **Marker marker=  mMap.addMarker(new MarkerOptions().position(new
                          LatLng(la[n], lo[n])).title("" + namefrag[n]));**
                    mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
                        @Override
                        public boolean onMarkerClick(Marker marker) {
                           // Log.i("okkk", " On marker Click  ");
                            AlertDialog.Builder alertadd = new AlertDialog.Builder(getActivity());
                            LayoutInflater factory = LayoutInflater.from(getActivity());
                            final View view = factory.inflate(R.layout.alert, null);
                            TextView alertName=(TextView) view.findViewById(R.id.tv_name);
                            TextView alertDeal=(TextView) view.findViewById(R.id.tv_deal);
                            String temp=marker.getTitle();
                            for (int i=0;i<namefrag.length;i++)
                            {
                               // Log.i("okkk", " Name:  " + temp);
                                if (temp.equals(namefrag[i]))
                                {
                                    tempName=namefrag[i];
                                    tempDeal=dealfrag[i];
                                    Log.i("okkk", " Name:  " + namefrag[i]);
                                }
                            }
                            RatingBar alertRating=(RatingBar) view.findViewById(R.id.rb_alert);
                            alertRating.setNumStars(5);
                            alertRating.setRating(3.5f);
                            alertName.setText(tempName);
                            alertDeal.setText(tempDeal);
                            alertadd.setView(view);
                            alertadd.show();
                            return false;
                        }
                    });
                    Notifications(namefrag[l], distance[Index]);

in your onMarkerClick() return true.

@Override
public boolean onMarkerClick(Marker marker) {
    marker.showInfoWindow();
    return true;
}

像这样使用......

Marker marker=  mMap.addMarker(new MarkerOptions().position(new LatLng(la[n], lo[n])).title("" + namefrag[n])).icon(BitmapDescriptorFactory.fromResource(R.drawable.driver_img));

Have you set up the icon for your marker ?

map.addMarker(new MarkerOptions()
                .position(new LatLng(myLat, myLong))
                .title("Bla Bla").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));

I think it is not set up in your code. Kindly try to set up icon to marker.

Are you sure that your variables la[n] and lo[n] are double ?

If they are String, you can use Double.parseDouble(String) to convert them to double :

double lat = Double.parseDouble(la[n]);
double lon = Double.parseDouble(lo[n]);
Marker marker =  mMap.addMarker(new MarkerOptions().position(new
                      LatLng(lat, lon)).title("" + namefrag[n]));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM