指定一个点击监听器的信息窗口,无法导航到该网页谷歌地图V2 [英] Assign a click listener to the info window, cannot navigate to the webpage Google Maps V2

查看:232
本文介绍了指定一个点击监听器的信息窗口,无法导航到该网页谷歌地图V2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是,我不能点击一个标记的信息窗口自定义里面andoid地图V2显示的URLwww.news.com。
在XML布局文件我有:

 <的TextView
    机器人:ID =@ + ID /网络
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:自动链接=网
    机器人:背景=#ADD8E6
    机器人:文字=www.google.gr
    机器人:linksClickable =真/>

在Java的活动文件我有:

  mMap.setInfoWindowAdapter(新InfoWindowAdapter(){            //使用默认信息窗口框架
            @覆盖
            公共查看getInfoWindow(标记标记){
                返回null;
            }            //定义信息窗口的内容
            @覆盖
            公共查看getInfoContents(标记标记){                //从布局文件info_window_layout获取视图
                视图V = getLayoutInflater()膨胀(R.layout.infowindow_layout,NULL);                TextView的tvTitle =(TextView中)v.findViewById(R.id.title);
                tvTitle.setText(marker.getTitle());
                TextView的tvSnippet =(TextView中)v.findViewById(R.id.snippet);
                tvSnippet.setText(marker.getSnippet());               // URL
               最终的TextView tvURL =(TextView中)v.findViewById(R.id.web);
               tvURL.setText(www.news.com);
               Linkify.addLinks(tvURL,Linkify.WEB_URLS);
                // URL

链接是否正确显示与蓝色和下划线,但我发现它只是一个死链接。如果我们试图单击它什么也没有发生。我要做的,使链接是否有效?

新的code插入的java文件中:

  mMap.setInfoWindowAdapter(新InfoWindowAdapter(){        //使用默认信息窗口框架
        @覆盖
        公共查看getInfoWindow(标记标记){
            返回null;
        }        //定义信息窗口的内容
        @覆盖
        公共查看getInfoContents(标记标记){            //从布局文件info_window_layout获取视图
            视图V = getLayoutInflater()膨胀(R.layout.infowindow_layout,NULL);            TextView的tvTitle =(TextView中)v.findViewById(R.id.title);
            tvTitle.setText(marker.getTitle());
            TextView的tvSnippet =(TextView中)v.findViewById(R.id.snippet);
            tvSnippet.setText(marker.getSnippet());           // URL                最终的TextView tvWeb =(TextView中)v.findViewById(R.id.web);
                tvWeb.setOnClickListener(新View.OnClickListener(){
                    公共无效的onClick(查看视图){
                        意图viewIntent =新意图(Intent.ACTION_VIEW,Uri.parse(http://www.news.com));
                        startActivity(viewIntent);
                    }
                });

XML使用了相同的:

 <的TextView
    机器人:ID =@ + ID /网络
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:自动链接=网
    机器人:背景=#ADD8E6
    机器人:文字=www.news.com
    机器人:linksClickable =真/>

不过问题exists..URL链接不活跃,我无法打开的浏览器。

现在URL链接来打开手机浏览器,当我点击自定义信息窗口。

  mMap.addMarker(新的MarkerOptions()位置(经纬度新(39.686286,19.838443))标题(HI)片段(姓名,电话:1093595, 。网址:www.news.com)图标(BitmapDesc​​riptorFactory.fromResource(R.drawable.location_icon)));
    mMap.setOnInfoWindowClickListener(新OnInfoWindowClickListener(){
        @覆盖
        公共无效onInfoWindowClick(标记标记){
            意图viewIntent =新意图(Intent.ACTION_VIEW,Uri.parse(http://www.news.com));
            startActivity(viewIntent);
        }
    });

但我身边有300标记,并为每个标记我希望打开一个单独的URL链接。我怎样才能实现呢?

更新code:

  mMap.addMarker(新的MarkerOptions()位置(经纬度新(36.84449,22.99999))标题(KALOGRIA)片段(姓名:。麦西尼亚\\ nSurname:斯陶帕\\ nphone:99999999 \\ nwebsite:http://www.news.com/\").icon(BitmapDesc​​riptorFactory.fromResource(R.drawable.location_icon)));
mMap.setOnInfoWindowClickListener(新GoogleMap.OnInfoWindowClickListener()
    {
    @覆盖
    公共无效onInfoWindowClick(标记标记)
    {
        //串WEBURL = marker.getSnippet();
        串snippetStr = marker.getSnippet();
        字符串WEBURL = snippetStr.substring(snippetStr.lastIndexOf(网站:)+ 1);
        意图viewIntent =新意图(Intent.ACTION_VIEW,Uri.parse(WEBURL));
        startActivity(viewIntent);
    }
    });


解决方案

信息窗口是不是实时取景,而该视图呈现为一个图像到地图上。因此,仅查看响应单击作为一个整体视图。对于你的情况,我想你必须使用 GoogleMap.setOnInfoWindowClickListener ,然后检索Web串推出。

结果
[ UPDATE1 ]

也许你可以试试这个方法:

  mMap.setOnInfoWindowClickListener(新GoogleMap.OnInfoWindowClickListener()
{           @覆盖
           公共无效onInfoWindowClick(标记thisMarker)
           {                意图viewIntent =新意图(Intent.ACTION_VIEW,Uri.parse(http://www.news.com));
                startActivity(viewIntent);           }});

结果
[ UPDATE2 ]

有关的情况下,你有几个标记 S,并希望打开不同的活动点击每个<$ C时$ C>标记,那么一个解决方案是将活动信息,以标记为:

 标记标记= mMap.addMarker(新的MarkerOptions()
 。位置(...)
 。标题(...)
 是.snippet(http://www.news.com); //把你的活动信息在这里

,然后把它当点击标记

  @覆盖
公共无效onInfoWindowClick(标记thisMarker)
{
         ......
     串snippetStr = thisMarker.getSnippet();
     字符串WEBURL = snippetStr.substring(snippetStr.lastIndexOf(网站:)+ 1);
     意图viewIntent =新意图(Intent.ACTION_VIEW,Uri.parse(WEBURL));
     startActivity(viewIntent);
}

The problem is that I cannot click on the URL "www.news.com" displayed on andoid map v2 inside custom infowindow of a marker. In xml layout file I have:

<TextView
    android:id="@+id/web"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:autoLink="web"
    android:background="#ADD8E6"
    android:text="www.google.gr"
    android:linksClickable="true"/>

In Java activity file I have:

 mMap.setInfoWindowAdapter(new InfoWindowAdapter() {

            // Use default InfoWindow frame
            @Override
            public View getInfoWindow(Marker marker) {
                return null;
            }

            // Defines the contents of the InfoWindow
            @Override
            public View getInfoContents(Marker marker) {

                // Getting view from the layout file info_window_layout
                View v = getLayoutInflater().inflate(R.layout.infowindow_layout, null);

                TextView tvTitle = (TextView) v.findViewById(R.id.title);
                tvTitle.setText(marker.getTitle());
                TextView tvSnippet = (TextView) v.findViewById(R.id.snippet);
                tvSnippet.setText(marker.getSnippet());

               // URL
               final TextView tvURL =(TextView) v.findViewById(R.id.web);
               tvURL.setText("www.news.com");
               Linkify.addLinks(tvURL, Linkify.WEB_URLS);
                // URL

The link is showing properly with blue color and underline, but I found the its just a dead link. Nothing is happening if we try to click it. What I have to do to make the link active?

New code inserted inside java file:

 mMap.setInfoWindowAdapter(new InfoWindowAdapter() {

        // Use default InfoWindow frame
        @Override
        public View getInfoWindow(Marker marker) {
            return null;
        }

        // Defines the contents of the InfoWindow
        @Override
        public View getInfoContents(Marker marker) {

            // Getting view from the layout file info_window_layout
            View v = getLayoutInflater().inflate(R.layout.infowindow_layout, null);

            TextView tvTitle = (TextView) v.findViewById(R.id.title);
            tvTitle.setText(marker.getTitle());
            TextView tvSnippet = (TextView) v.findViewById(R.id.snippet);
            tvSnippet.setText(marker.getSnippet());

           // URL

                final TextView tvWeb =(TextView) v.findViewById(R.id.web);
                tvWeb.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View view) {
                        Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.news.com"));
                        startActivity(viewIntent);
                    }
                });

XML used the same:

    <TextView
    android:id="@+id/web"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:autoLink="web"
    android:background="#ADD8E6"
    android:text="www.news.com"
    android:linksClickable="true"/>

Still problem exists..URL link is not active, I cannot open browser.

Now URL link is opening to mobile browser when I click on custom infowindow.

 mMap.addMarker(new MarkerOptions().position(new LatLng(39.686286, 19.838443)).title("Hi").snippet("Name, Surname, phone: 1093595, website: www.news.com").icon(BitmapDescriptorFactory.fromResource(R.drawable.location_icon)));
    mMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
        @Override
        public void onInfoWindowClick(Marker marker) {
            Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.news.com"));
            startActivity(viewIntent);


        }
    });

But I have around 300 markers and for each marker I wish to open a separate URL link. How can I implement this?

UPDATE CODE:

mMap.addMarker(new MarkerOptions().position(new LatLng(36.84449, 22.99999)).title("KALOGRIA").snippet("Name: Messinia \nSurname: Stoupa \nphone: +99999999 \nwebsite: http://www.news.com/").icon(BitmapDescriptorFactory.fromResource(R.drawable.location_icon)));


mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener()
    {
    @Override
    public void onInfoWindowClick(Marker marker)
    {
        //String webUrl = marker.getSnippet();
        String snippetStr = marker.getSnippet();
        String webUrl = snippetStr.substring(snippetStr.lastIndexOf("website:") + 1);
        Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(webUrl));
        startActivity(viewIntent);
    }
    });

解决方案

Info window is not a live View, rather the view is rendered as an image onto the map. So the view only response click as a whole view. For your case I suppose you have to use GoogleMap.setOnInfoWindowClickListener, and then retrieve the web string to launch.


[UPDATE1]

Maybe you could try this way:

mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener()
{

           @Override
           public void onInfoWindowClick(Marker thisMarker)
           {

                Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.news.com"));
                startActivity(viewIntent);                 

           }

});


[UPDATE2]

For the case you have several Markers, and want to open different Activity when click each Marker, then one solution is to put Activity info to Marker's Snippet as:

Marker marker = mMap.addMarker(new MarkerOptions()
 .position(...)
 .title(...)
 .snippet("http://www.news.com"); //put your activity info here

and then get it when click Marker:

@Override
public void onInfoWindowClick(Marker thisMarker)
{
         ... ...
     String snippetStr = thisMarker.getSnippet();
     String webUrl = snippetStr.substring(snippetStr.lastIndexOf("website:") + 1);
     Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(webUrl));
     startActivity(viewIntent);
}

这篇关于指定一个点击监听器的信息窗口,无法导航到该网页谷歌地图V2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆