热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

为Android标记信息窗口添加图像-AddanimageforAndroidmarkerinfowindow

Immakinganandroidapp.Inthisapp,therearemarkersofsomehotelsandwhenuserclickonthe

I'm making an android app. In this app, there are markers of some hotels and when user click on the marker info window appears and it should be like following image. (This is a web application)

我正在制作一个Android应用程序。在这个应用程序中,有一些酒店的标记,当用户点击标记信息窗口时,它应该像下面的图像。 (这是一个Web应用程序)

Marker info window

I have a list view in my navigation drawer fragment and map fragment has the markers.

我的导航抽屉片段中有一个列表视图,地图片段有标记。

This is my code before I try to load image for the info window in MainActivity.java.

在我尝试为MainActivity.java中的信息窗口加载图像之前,这是我的代码。

  // Load Hotels
    private class GetHotelTask extends AsyncTask {
        @Override
        protected String doInBackground(String... data) {
            String identifier = data[0];

            // Toast.makeText(getContext(), "Manuli "+identifier, Toast.LENGTH_LONG ).show();
            // Create a new HttpClient and Post Header
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://api.ayubo.lk/android/retrievehotels");
            HttpResponse respOnse= null;
            String respOnseStr= null;

            try {
                //add data
                List nameValuePairs = new ArrayList(1);
                nameValuePairs.add(new BasicNameValuePair("long", data[0]));
                nameValuePairs.add(new BasicNameValuePair("lat", data[1]));
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                //execute http post
                respOnse= httpclient.execute(httppost);
                respOnseStr= EntityUtils.toString(response.getEntity());

            } catch (ClientProtocolException e) {
                e.printStackTrace();

            } catch (IOException e) {
                e.printStackTrace();
            }

            return responseStr;
        }

        protected void onPostExecute(String result) {

            try {
                JSONArray jObj = new JSONArray(result);

                for(int a=0;a

Here is the listview call of hotels inside MainActivity.java.

这是MainActivity.java内酒店的listview调用。

// Hotels
            case 0:
                if (A == 0){
                    Bundle bundle = new Bundle();
                    bundle.putString("restaurants", "Default");
                    fragmentObj = new GoogleMapsFragment();
                    fragmentObj.setArguments(bundle);

                    if (!sclItems.contains(0)){
                        new GetHotelTask().execute(longtitude, latitude);
                        sclItems.add(0);
                    }else {
                        removeHotels();
                        sclItems.remove((Integer)0);
                    }
                    A = 1;
                }else {
                    if (!sclItems.contains(0)){
                        new GetHotelTask().execute(longtitude, latitude);
                        sclItems.add(0);
                    }else {
                        removeHotels();
                        sclItems.remove((Integer)0);
                    }
                }
                break;

I've tried adding info_window_layout.xml and here is the code.

我已经尝试添加info_window_layout.xml,这是代码。




    
        
        
        
    


But, I cannot load my info window like in the image. I've tried several solutions including this and any of that didn't give me a solution.

但是,我无法像在图像中那样加载我的信息窗口。我尝试了几种解决方案,包括这个,其中任何一个都没有给我一个解决方案。

Can someone please help me with this?

有人可以帮我这个吗?

Thanks in advance. :)

提前致谢。 :)

  • Error -
  • 错误 -

error

4 个解决方案

#1


2  

Figured it out finally. :D

终于搞清楚了。 :d

Changed the info_window_layout.xml like this.

像这样更改了info_window_layout.xml。


    

        

        
        
    

Then added a new class called, ManiInfoAdapter.java

然后添加了一个名为ManiInfoAdapter.java的新类

class MapInfoWindowAdapter implements GoogleMap.InfoWindowAdapter {

    private LayoutInflater inflater;
    private Context context;

    public MapInfoWindowAdapter(Context context){
        inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
        this.cOntext= context;
    }

    @Override
    public View getInfoWindow(Marker marker) {
        // Getting view from the layout file
        View v = inflater.inflate(R.layout.info_window_layout, null);

        TextView title = (TextView) v.findViewById(R.id.title);
        title.setText(marker.getTitle());

        TextView address = (TextView) v.findViewById(R.id.distance);
        address.setText(marker.getSnippet());

        ImageView iv = (ImageView) v.findViewById(R.id.markerImage);
        iv.setImageResource(R.drawable.ic_attraction1);

        return v;
    }

    @Override
    public View getInfoContents(Marker marker) {
        return null;
    }
}

Now working as expected. :)

现在按预期工作。 :)

#2


1  

Try this code :

试试这段代码:

   Marker kiel=FragmentLeft.map.addMarker(new MarkerOptions().position(new LatLng(Double.parseDouble(p.getLatitude()), Double.parseDouble(p.getLongitude())))
                .title(p.getEventName()).snippet(getLocationStringAddress(new LatLng(Double.parseDouble(p.getLatitude()), Double.parseDouble(p.getLongitude()))))
                .icon(BitmapDescriptorFactory.fromResource(R.mipmap.map_set_marker)));
        markers.put(kiel.getId(),"http://"+strPhoto);
        kiel.setInfoWindowAnchor(1.95f,0.0f);
        hMarker.put(kiel,p);
        map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
            @Override
            public View getInfoWindow(Marker arg0) {
                View myCOntentView= flipscreen.this.getLayoutInflater().inflate(R.layout.custommarker, null);
                TextView tvTitle = ((TextView) myContentView.findViewById(R.id.title));
                tvTitle.setText(arg0.getTitle());
                TextView tvSnippet = ((TextView) myContentView.findViewById(R.id.snippet));
                tvSnippet.setText(arg0.getSnippet());
                ImageView imgMarkerImage=(ImageView)myContentView.findViewById(R.id.imgMarkerImage);
                System.out.println("List of Event Photos = " + strPhoto);
                Picasso.with(flipscreen.this).load(markers.get(arg0.getId())).into(imgMarkerImage);
                return myContentView;
            }
            @Override
            public View getInfoContents(Marker marker) {
                return null;
            }
        });
        map.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
            @Override
            public void onInfoWindowClick(Marker marker) {
                Iterator myVeryOwnIterator = hMarker.keySet().iterator();
                while(myVeryOwnIterator.hasNext()) {
                    Marker key=(Marker)myVeryOwnIterator.next();
                    if(marker.getId().equals(key.getId())){
                        Event value=(Event)hMarker.get(key);
                        Activity_Event_Details.setEventDetails(value);
                        startActivity(new Intent(flipscreen.this,Activity_Event_Details.class));

                    }
                }
            }
        });

#3


1  

I have tried to do the same for my app. I couldn't load images into the marker as I wanted.

我试过为我的应用做同样的事情。我无法按照我的意愿将图像加载到标记中。

So what I did was.

所以我做的是。

  1. Created an xml layout maps_info_window_blue

    创建了一个xml布局maps_info_window_blue

  2. I included into my map layout.

    我加入了我的地图布局。

    
    
    
    
    
    
    
    
    

For me the requirement was to have the marker info window in the center. You can set it where ever you want.

对我来说,要求是将标记信息窗口放在中心。您可以根据需要进行设置。

  1. In order to give the illusion of a marker, I always set LatLng which I want to be the center of the map (CameraPosition target is set to the LatLng I want)
  2. 为了给出标记的错觉,我总是设置LatLng,我想成为地图的中心(CameraPosition目标设置为我想要的LatLng)

#4


1  

Try using info window adapter. This may help you i think.

尝试使用信息窗口适配器。这可能对你有所帮助。

mMap.setInfoWindowAdapter(setMarkerWindow());




    private GoogleMap.InfoWindowAdapter setMarkerWindow() {
                return new GoogleMap.InfoWindowAdapter() {
                    @Override
                    public View getInfoWindow(Marker marker) {
                        View myCOntentView= getLayoutInflater().inflate(
                                R.layout.map_info_window, null);
                        myContentView.setBackgroundColor(Color.TRANSPARENT);
                        TextView tvTitle = ((TextView) myContentView
                                .findViewById(R.id.title));
 tvTitle.setText(marker.getTitle());
                       ......
                        return myContentView;
                    }

                    @Override
                    public View getInfoContents(Marker marker) {
                        return null;
                    }
                };
            }

推荐阅读
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 本文介绍了如何使用PHP向系统日历中添加事件的方法,通过使用PHP技术可以实现自动添加事件的功能,从而实现全局通知系统和迅速记录工具的自动化。同时还提到了系统exchange自带的日历具有同步感的特点,以及使用web技术实现自动添加事件的优势。 ... [详细]
  • 微软头条实习生分享深度学习自学指南
    本文介绍了一位微软头条实习生自学深度学习的经验分享,包括学习资源推荐、重要基础知识的学习要点等。作者强调了学好Python和数学基础的重要性,并提供了一些建议。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • GetWindowLong函数
    今天在看一个代码里头写了GetWindowLong(hwnd,0),我当时就有点费解,靠,上网搜索函数原型说明,死活找不到第 ... [详细]
  • 生成式对抗网络模型综述摘要生成式对抗网络模型(GAN)是基于深度学习的一种强大的生成模型,可以应用于计算机视觉、自然语言处理、半监督学习等重要领域。生成式对抗网络 ... [详细]
  • 云原生边缘计算之KubeEdge简介及功能特点
    本文介绍了云原生边缘计算中的KubeEdge系统,该系统是一个开源系统,用于将容器化应用程序编排功能扩展到Edge的主机。它基于Kubernetes构建,并为网络应用程序提供基础架构支持。同时,KubeEdge具有离线模式、基于Kubernetes的节点、群集、应用程序和设备管理、资源优化等特点。此外,KubeEdge还支持跨平台工作,在私有、公共和混合云中都可以运行。同时,KubeEdge还提供数据管理和数据分析管道引擎的支持。最后,本文还介绍了KubeEdge系统生成证书的方法。 ... [详细]
  • 这是原文链接:sendingformdata许多情况下,我们使用表单发送数据到服务器。服务器处理数据并返回响应给用户。这看起来很简单,但是 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • Java容器中的compareto方法排序原理解析
    本文从源码解析Java容器中的compareto方法的排序原理,讲解了在使用数组存储数据时的限制以及存储效率的问题。同时提到了Redis的五大数据结构和list、set等知识点,回忆了作者大学时代的Java学习经历。文章以作者做的思维导图作为目录,展示了整个讲解过程。 ... [详细]
  • 本文介绍了C++中省略号类型和参数个数不确定函数参数的使用方法,并提供了一个范例。通过宏定义的方式,可以方便地处理不定参数的情况。文章中给出了具体的代码实现,并对代码进行了解释和说明。这对于需要处理不定参数的情况的程序员来说,是一个很有用的参考资料。 ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • JavaSE笔试题-接口、抽象类、多态等问题解答
    本文解答了JavaSE笔试题中关于接口、抽象类、多态等问题。包括Math类的取整数方法、接口是否可继承、抽象类是否可实现接口、抽象类是否可继承具体类、抽象类中是否可以有静态main方法等问题。同时介绍了面向对象的特征,以及Java中实现多态的机制。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
author-avatar
手机用户2602906131
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有