当我在模拟器中单击地图标记的InfoWindow时,它可以正常工作,但在物理设备上不会捕获点击。这是我的代码。
public class FragmentTab1 extends Fragment implements GoogleMap.OnInfoWindowClickListener {
private static GoogleMap googleMap = null;
public View onCreateView(final LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View layout = inflater.inflate(R.layout.fragment_tab1, container, false);
googleMap = null;
db = new DatabaseHelper(MyApplication.getAppContext());
shopDataArrayList = db.getShops();
db.closeDB();
mapMarkerData.clear();
googleMap = null;
initilizeMap();
inflateMapMarker(shopDataArrayList);
onMapReady();
return layout;
}
//To initilize googleMap object.
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.home_map)).getMap();
googleMap.setMyLocationEnabled(true);
googleMap.getUiSettings().setZoomControlsEnabled(true);
googleMap.getUiSettings().setCompassEnabled(true);
googleMap.getUiSettings().setAllGesturesEnabled(true);
googleMap.setInfoWindowAdapter(new CustomInfoWindowAdapter());
googleMap.setOnInfoWindowClickListener(this);
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(MyApplication.getAppContext(), "Sorry! unable to create maps", Toast.LENGTH_SHORT).show();
}
}
}
//For the first time, this will draw all the points on the map.
public void onMapReady() {
for (int i = 0; i < mapMarkerData.size() - 1; i++) {
Log.d("TAG","In onMapReady");
Marker m = placeMarker(mapMarkerData.get(i));
marker_data.put(m, mapMarkerData.get(i));
marker_key.put((i + 1) + "", m);
}
}
//This is to inflate the mapMarkers with offerData.
private void inflateMapMarker(ArrayList<ShopData> mShopDataArray) {
for (int i = 0; i < mShopDataArray.size(); i++) {
String[] coordinates = mShopDataArray.get(i).getCoordinates().split(",");
double lat = Double.parseDouble(coordinates[0].substring(1));
double lng = Double.parseDouble(coordinates[1].substring(0, coordinates[1].length() - 1));
MapMarkerData lld = new MapMarkerData(lat,lng,mShopDataArray.get(i).getLogo_img(),mShopDataArray.get(i).getShop_name());
mapMarkerData.add(lld);
Log.d("TAG",lat+" "+lng);
}
}
public Marker placeMarker(MapMarkerData mapMarkerData) {
LatLng location = new LatLng(mapMarkerData.getLat(), mapMarkerData.getLng());
Marker m = googleMap.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.defaultMarker(Constants.marker_color[1]))
.title(mapMarkerData.getShop_name())
.position(location)
.visible(true));
return m;
}
@Override
public void onInfoWindowClick(Marker marker) {
Toast.makeText(getActivity(),"onInfoWidnow",Toast.LENGTH_SHORT);
Intent intent = new Intent(FragmentTab1.this.getActivity(), ShopActivity.class);
//This is to send offerData accross the activites.
//de.greenrobot.event.EventBus.getDefault().postSticky(mofferData.get(position));
FragmentTab1.this.startActivityForResult(intent, 0);
return;
}
private class CustomInfoWindowAdapter implements GoogleMap.InfoWindowAdapter {
private View view;
private TextView textView;
private ImageView imageView;
public CustomInfoWindowAdapter(){
view = getActivity().getLayoutInflater().inflate(R.layout.custom_info_window, null);
textView = (TextView)view.findViewById(R.id.infoWindowText);
imageView = (ImageView) view.findViewById(R.id.infoWindowImg);
}
@Override
public View getInfoWindow(Marker marker) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
final ImageLoader imageLoader = new VolleyHandler().getImageLoader();
imageLoader.get(marker_data.get(marker).getLogo_img(), new ImageLoader.ImageListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Image Load Error: " + error.getMessage());
}
@Override
public void onResponse(ImageLoader.ImageContainer response, boolean arg1) {
if (response.getBitmap() != null) {
// load image into imageview
Log.d(TAG, "imaged is being loaded");
imageView.setImageBitmap(response.getBitmap());
}
}
});
textView.setText(marker_data.get(marker).getShop_name());
return view;
}
}
为什么它不能在物理设备上工作但在仿真器上工作?