【问题标题】:Android google map location item click with starting new activityAndroid 谷歌地图位置项目点击开始新活动
【发布时间】:2014-09-18 18:14:09
【问题描述】:
     map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() 
                    {
                        public void onInfoWindowClick(Marker marker) 
                        {
                           Intent intent = new Intent(NearbyAttractions.this,Activity2.class);
                           intent.putExtra("Clubname", ParseXMLMethods.getValue(e, KEY_TITLE));
                           intent.putExtra("Username", Username);
                           intent.putExtra("ID2", UserID);
                           startActivity(intent);


                        }
                    });

总是得到最后一个位置名称,并且我在没有声明 final 的情况下将 e 声明为最终变量的位置出现错误。我的要求是,如果我单击特定标记开始新活动,我会在其中传递位置名称。

【问题讨论】:

    标签: android google-maps


    【解决方案1】:

    InfoWindow 不是实时视图,所以这是我所做的:

    public class CustomInfoWindowAdpater implements GoogleMap.InfoWindowAdapter,Picasso.Listener {
            @Override
            public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) {
    
            }
    
            private final View view;
    
            public CustomInfoWindowAdpater() {
                view = getLayoutInflater()
                        .inflate(R.layout.custominfowindow, null);
            }
    
            public View getInfoWindow(final Marker marker) {
                MainApplication.currentlyClickedMarker = marker;
                final LinearLayout linearLayout = (LinearLayout)view.findViewById(R.id.ll_custominfowindow);
                linearLayout.setTag(marker.getId());
    
    
                GoogleMapFragment.this.marker = marker;
    
                String url = null;
    
                if (marker.getId() != null && markers != null && markers.size() > 0) {
                    if ( markers.get(marker.getId()) != null &&
                            markers.get(marker.getId()) != null) {
                        url = markers.get(marker.getId());
                    }
                }
    
               final ImageView image = ((ImageView) view.findViewById(R.id.badge));
    
    
                //Get the Image from web using Picasso and update the info contents
                if (url != null && !url.equalsIgnoreCase("null")
                        && !url.equalsIgnoreCase("")) {
                    Picasso.with(GoogleMapFragment.this).load(Uri.parse(url)).resize(50,50)
                            .into(image, new Callback() {
                                @Override
                                public void onSuccess() {
                                    getInfoContents(marker);
                                }
    
                                @Override
                                public void onError() {
    
                                }
                            });
                }
                else{
                    image.setImageResource(R.drawable.ic_launcher);
                }
    
                final String title = marker.getTitle();
                final TextView titleUi = ((TextView) view.findViewById(R.id.title));
                if (title != null) {
                    titleUi.setText(title);
                } else {
                    titleUi.setText("");
                }
    
                final String snippet = marker.getSnippet();
                final TextView snippetUi = ((TextView) view
                        .findViewById(R.id.snippet));
                if (snippet != null) {
                    snippetUi.setText("");
                } else {
                    snippetUi.setText("");
                }
    
                return view;
            }
    

    ...

    @Override
        public void onCreate(Bundle savedInstanceState) {   
            super.onCreate(savedInstanceState);
         googleMap.setInfoWindowAdapter(new CustomInfoWindowAdpater());
    }
    

    ...

    @Override
        public void onInfoWindowClick(Marker marker) {
            // open the application
            Intent intent = new Intent(GoogleMapFragment.this,SplashScreenAppPro.class);
            // SplashScreen
            intent.putExtra("id",marker.getSnippet());
            intent.putExtra("nom_profil",  marker.getTitle());
            startActivity(intent);
    
    
        }
    

    *你的Activity/Fragment必须实现GoogleMap.OnInfoWindowClickListener

    【讨论】:

    • Thnx.intent.putExtra("nom_profil", marker.getTitle());这条线对我的应用有很大帮助
    • @ChatterjeeKaushik Np,如果它对你有用,别忘了接受我的回答
    • 实际上对 urs 的总体回答对我的要求并不完美。你的代码的一个特定行对我有很大的帮助,我已经提到了@Abdellah
    猜你喜欢
    • 2012-03-04
    • 2021-07-23
    • 2018-03-18
    • 2015-03-23
    • 2020-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多