Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在mapreday信息窗口_Android_Google Maps - Fatal编程技术网

Android 在mapreday信息窗口

Android 在mapreday信息窗口,android,google-maps,Android,Google Maps,构建基于位置的应用程序 单击标记时,我会将标记添加到“地图和信息”窗口 代码: public void onMapReady(GoogleMap googleMap) { mMap = googleMap; UiSettings uiSettings = mMap.getUiSettings(); uiSettings.setMyLocationButtonEnabled(false); uiSettings.setMapToolbarEnabled(false)

构建基于位置的应用程序

单击标记时,我会将标记添加到“地图和信息”窗口

代码:

public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    UiSettings uiSettings = mMap.getUiSettings();
    uiSettings.setMyLocationButtonEnabled(false);
    uiSettings.setMapToolbarEnabled(false);

    mMapCoastLocationService.init(mMap);

    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        return;
    }
    mMap.setMyLocationEnabled(true);

    // set the markers - new
    mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
        @Override
        public View getInfoWindow(Marker marker) {
            return null;
        }

        @Override
        public View getInfoContents(Marker marker) {
            View view = LayoutInflater.from(context).inflate(R.layout.map_marker_info_contents, null, false);
            //ImageView icon = (ImageView) view.findViewById(R.id.marker_info_window_icon);
            //icon.setImageResource(R.drawable.info);
            TextView title = (TextView) view.findViewById(R.id.marker_info_window_title);
            title.setText(marker.getTitle());
            return view;
        }
    });

    mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
        @Override
        public void onInfoWindowClick(Marker marker) {
            Integer coastId = mMapCoastLocationService.getCoastIdByMarker(marker);
            startCoastDetailsActivity(coastId);
        }
    });


    mFocusMyLocationButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            focusMyLocation();
        }
    });
}
用于标记的xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/marker_info_window_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:contentDescription="info image"
        android:src="@drawable/info" />

    <TextView
        android:id="@+id/marker_info_window_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"`enter code here`
        android:layout_marginLeft="@dimen/marker_text_margin"
        android:layout_marginStart="@dimen/marker_text_margin"
        android:text="example"
        android:textColor="#000"/>

</LinearLayout>

问题是,当我第一次运行应用程序时,当我单击一个标记时,我只得到文本,而不是图标,而且单击不起作用

第二次一切都很好


有什么帮助吗?

这是因为谷歌地图信息窗口在显示信息窗口之前(单击时)会将其渲染为位图 这意味着,如果您有来自web的图像源或大型本地资源要加载到InfoWindow内部的ImageView中,则在InfoWindow渲染完成之前可能无法完成

第二次加载图像时,信息窗口已呈现,因此它将显示

解决方案(使用Glide如下所示):

公共类MarkerInfoWindowAdapter实现GoogleMap.InfoWindowAdapter、GoogleMap.OnInfoWindowClickListener{
私有静态最终字符串标记=MarkerInfoWindowAdapter.class.getName();;
私有静态上下文mContext;
私有静态视图MapInfo窗口;
私有静态图像视图信息窗口图标;
私有静态文本视图infoWindowTitle;
私有静态文本视图信息窗口详细信息;
私有静态TextView infoWindowCount;
public MarkerInfoWindowAdapter(上下文){
mContext=上下文;
MapInfo窗口=((SessionActivity)上下文).GetLayoutFlater().inflate(R.layout.marker\u info\u layout,null);
infoWindowIcon=(ImageView)MapInfo窗口.findViewById(R.id.session_图标);
infoWindowTitle=(TextView)mapInfoWindow.findviewbyd(R.id.title);
infoWindowDetails=(TextView)mapInfoWindow.findviewbyd(R.id.snippet);
infoWindowCount=(TextView)MapInfo Window.findViewById(R.id.attenders\U计数);
}
@凌驾
公共视图getInfoWindow(标记器){
返回管理器markerinfo(marker);
}
@凌驾
公共视图getInfoContents(标记器){
Log.i(标记“刷新”);
刷新信息窗口(标记);
返回null;
}
@凌驾
公用无效信息窗口单击(标记){
单击信息项(getContext(),标记);
}
专用视图管理器标记信息(标记){
if(marker.getTitle()==null | | marker.getTitle().length()==0 | | marker.getTitle().equalsIgnoreCase(“”){
Log.i(标记“无信息”);
marker.hideInfo窗口();
返回null;
}否则{
Log.i(标签“常规信息”);
返回selectMarker(marker);
}
}
专用视图选择标记(最终标记){
if(MapHelper.newSessionMarker!=null | | marker.getTitle().equalsIgnoreCase(mContext.getString(R.string.session_create))){
infoWindowTitle.setText(marker.getTitle());
infoWindowDetails.setText(LocationHelper.getCountryAddressFromCoords(
marker.getPosition()纬度,
marker.getPosition().longitude));
infoWindowCount.setVisibility(View.INVISIBLE);
使用(mContext)滑动
.load(ParseUser.getCurrentUser().getString(“用户图像url”))
.占位符(R.drawable.add_会话)
.bitmapTransform(新CropCircletTransformation(mContext))
.listener(新的RequestListener(){
@凌驾
公共布尔onException(异常e、字符串模型、目标、布尔isFirstResource){
Log.i(标签,“错误加载图像”);
返回false;
}
@凌驾
公共布尔onResourceReady(可提取资源、字符串模型、目标、,
布尔值(从MemoryCache开始,布尔值为FirstResource){
Log.i(标记“成功加载图像”);
获取信息内容(标记);
返回false;
}
})
.错误(R.drawable.add_会话)
.into(信息窗口图标);
返回MapInfo窗口;
}否则{
SessionObject session=MapHelper.selectedSessionByUser;
infoWindowTitle.setText(session.getSessionMarker().getTitle());
infoWindowDetails.setText(LocationHelper.getCountryAddressFromCoords(
session.getSessionMarker().getPosition().latitude,
getSessionMarker().getPosition().longitude));
infoWindowCount.setVisibility(View.VISIBLE);
if(session.getAttenderScont()>0){
infoWindowCount.setText(“+session.getAttenderScont());
infoWindowCount.setVisibility(View.VISIBLE);
}
否则{
infoWindowCount.setVisibility(View.INVISIBLE);
}
if(会话!=null){
Log.d(标记“选择会话:”);
Log.d(标记,“会话标题:+Session.getSessionObject().getString(“标题”));
Log.d(标记,“会话映像:+Session.getSessionObject().getString(“会话映像url”));
Log.d(标记,“会话地理点:+marker.getPosition().latitude+”,“
+marker.getPosition().longitude);
Log.d(标记为“sessionattenders:+Session.getAttendersCount());
if(session.getSessionObject().getString(“地址”)!=null&&
session.getSessionObject().getString(“地址”).length()>0){
infoWindowDetails.setText(session.getSessionObject().getString(“地址”);
}
int defaultIcon=Constants.sessionTypesList.get(session.getSessionObject().getInt(“类型”)).getResources()[0];
试一试{
public class MarkerInfoWindowAdapter implements GoogleMap.InfoWindowAdapter, GoogleMap.OnInfoWindowClickListener {
    private static final String TAG = MarkerInfoWindowAdapter.class.getName();;

    private static Context mContext;
    private static View mapInfoWindow;
    private static ImageView infoWindowIcon;
    private static TextView infoWindowTitle;
    private static TextView infoWindowDetails;
    private static TextView infoWindowCount;

    public MarkerInfoWindowAdapter(Context context){
        mContext = context;
        mapInfoWindow = ((SessionsActivity) context).getLayoutInflater().inflate(R.layout.marker_info_layout, null);
        infoWindowIcon = (ImageView) mapInfoWindow.findViewById(R.id.session_icon);
        infoWindowTitle = (TextView) mapInfoWindow.findViewById(R.id.title);
        infoWindowDetails = (TextView) mapInfoWindow.findViewById(R.id.snippet);
        infoWindowCount = (TextView) mapInfoWindow.findViewById(R.id.attenders_count);
    }

    @Override
    public View getInfoWindow(Marker marker) {
        return manageMarkerInfo(marker);
    }

    @Override
    public View getInfoContents(Marker marker) {
        Log.i(TAG, "Refresh");
        refreshInfoWindow(marker);
        return null;
    }

    @Override
    public void onInfoWindowClick(Marker marker) {
        MapHelper.clickInfoItem(getContext(), marker);
    }

    private View manageMarkerInfo(Marker marker){
        if (marker.getTitle() == null || marker.getTitle().length() == 0 || marker.getTitle().equalsIgnoreCase("")) {
            Log.i(TAG, "NO Info");
            marker.hideInfoWindow();
            return null;
        } else{
            Log.i(TAG, "Regular Info");
            return selectMarker(marker);
        }
    }

    private View selectMarker(final Marker marker) {
        if (MapHelper.newSessionMarker != null || marker.getTitle().equalsIgnoreCase(mContext.getString(R.string.session_create))) {
            infoWindowTitle.setText(marker.getTitle());
            infoWindowDetails.setText(LocationHelper.getCountryAddressFromCoords(
                    marker.getPosition().latitude,
                    marker.getPosition().longitude));

            infoWindowCount.setVisibility(View.INVISIBLE);
            Glide.with(mContext)
                    .load(ParseUser.getCurrentUser().getString("user_image_url"))
                    .placeholder(R.drawable.add_session)
                    .bitmapTransform(new CropCircleTransformation(mContext))
                    .listener(new RequestListener<String, GlideDrawable>() {
                        @Override
                        public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                            Log.i(TAG, "Error loading Image");
                            return false;
                        }

                        @Override
                        public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target,
                                                       boolean isFromMemoryCache, boolean isFirstResource) {
                            Log.i(TAG, "Success loading Image");
                            getInfoContents(marker);
                            return false;
                        }
                    })
                    .error(R.drawable.add_session)
                    .into(infoWindowIcon);
            return mapInfoWindow;
        } else{
            SessionObject session = MapHelper.selectedSessionByUser;
            infoWindowTitle.setText(session.getSessionMarker().getTitle());
            infoWindowDetails.setText(LocationHelper.getCountryAddressFromCoords(
                    session.getSessionMarker().getPosition().latitude,
                    session.getSessionMarker().getPosition().longitude));

            infoWindowCount.setVisibility(View.VISIBLE);
            if (session.getAttendersCount() > 0) {
                infoWindowCount.setText("" + session.getAttendersCount());
                infoWindowCount.setVisibility(View.VISIBLE);
            }
            else {
                infoWindowCount.setVisibility(View.INVISIBLE);
            }
            if (session != null) {
                Log.d(TAG, "Select Session:");
                Log.d(TAG, "Session Title: " + session.getSessionObject().getString("title"));
                Log.d(TAG, "Session Image: " + session.getSessionObject().getString("session_image_url"));
                Log.d(TAG, "Session GeoPoints: " + marker.getPosition().latitude + ", "
                        + marker.getPosition().longitude);
                Log.d(TAG, "Session Attenders:" + session.getAttendersCount());
                if(session.getSessionObject().getString("address") != null &&
                        session.getSessionObject().getString("address").length() > 0){
                    infoWindowDetails.setText(session.getSessionObject().getString("address"));
                }

                int defaultIcon = Constants.sessionTypesList.get(session.getSessionObject().getInt("type")).getResources()[0];
                try {
                    Glide.with(mContext)
                            .load(session.getSessionObject().getString("session_image_url"))
                            .placeholder(defaultIcon)
                            .bitmapTransform(new CropCircleTransformation(mContext))
                            .listener(new RequestListener<String, GlideDrawable>() {
                                @Override
                                public boolean onException(Exception e, String model, Target<GlideDrawable> target,
                                                           boolean isFirstResource) {
                                    Log.i(TAG, "Error loading Image");
                                    return false;
                                }

                                @Override
                                public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target,
                                                               boolean isFromMemoryCache, boolean isFirstResource) {
                                    Log.i(TAG, "Success loading Image");
                                    getInfoContents(marker);
                                    return false;
                                }
                            })
                            .error(defaultIcon)
                            .into(infoWindowIcon);
                    return mapInfoWindow;
                } catch (Exception e1) {
                    e1.printStackTrace();
                    return mapInfoWindow;
                }
            }else{
                return mapInfoWindow;
            }
        }
    }

    private void refreshInfoWindow(Marker marker){
        if (marker != null && marker.isInfoWindowShown()) {
            Log.i(TAG, "Success loading Image");
            marker.hideInfoWindow();
            marker.showInfoWindow();
        }
    }

    private Context getContext() {
        return mContext;
    }

    public SessionObject getSessionFromMarker(Marker marker) {
        for (SessionObject session : ((SessionsActivity)getContext()).sessionsList) {
            if (marker.getId().equals(session.getSessionMarker().getId())) {
                return session;
            }
        }
        return null;
    }
}