Android的谷歌地图API V2:打开自定义信息窗口上标记的右侧 [英] Android Google Map API V2 : Open Custom Info Window on Right Side of Marker

查看:227
本文介绍了Android的谷歌地图API V2:打开自定义信息窗口上标记的右侧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有集成谷歌地图API V2为Android。我想有一个自定义信息窗口,在我的标记中的onclick。截至这是好的。我有整合它。

I have Integrated Google MAP API V2 for Android. I want to have a Custom Info Window at Onclick of My Marker. Up to that it is fine. i have integrate it.

我想:我想告诉我的自定义信息窗口上的标记而不是顶部标记的右侧

What I want : I want to Show my Custom Info Window on Right Side of Marker Instead of Top of the Marker.

下面是code我使用的:

Below is the Code I am Using :

public class MainActivity extends FragmentActivity {

    private MainMapFragement mapFragment;
    private HashMap<Marker, EventInfo> eventMarkerMap;


    Marker ThirdMarker;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mapFragment = new MainMapFragement();
        // FragmentTransaction ft = getFragmentManager().beginTransaction();
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.add(R.id.map, mapFragment);
        ft.commit();

    }

    @Override
    protected void onStart() {
        super.onStart();
        setUpEventSpots();
    }

    private void setUpEventSpots() {
        // I'm going to make 2 EventInfo objects and place them on the map
        EventInfo firstEventInfo = new EventInfo(new LatLng(50.154, 4.35),
                "Right now - event", new Date(), "Party");
        EventInfo secondEventInfo = new EventInfo(new LatLng(51.25, 4.15),
                "Future Event", new Date(1032, 5, 25), "Convention");

        EventInfo thirdEventInfo = new EventInfo(new LatLng(23.25, 72.15),
                "Our Next Event", new Date(), "Ahmedabad-India");
        // this date constructor is deprecated but it's just to make a simple
        // example

        Marker firstMarker = mapFragment.placeMarker(firstEventInfo);
        Marker secondMarker = mapFragment.placeMarker(secondEventInfo);
        ThirdMarker = mapFragment.placeMarker(thirdEventInfo);
        eventMarkerMap = new HashMap<Marker, EventInfo>();
        eventMarkerMap.put(firstMarker, firstEventInfo);
        eventMarkerMap.put(secondMarker, secondEventInfo);
        eventMarkerMap.put(ThirdMarker, thirdEventInfo);

        // add the onClickInfoWindowListener
        mapFragment.getMap().setOnInfoWindowClickListener(
                new OnInfoWindowClickListener() {

                    @Override
                    public void onInfoWindowClick(Marker marker) {
                        EventInfo eventInfo = eventMarkerMap.get(marker);
                        Toast.makeText(
                                getBaseContext(),
                                "The date of "
                                        + eventInfo.getName()
                                        + " is "
                                        + eventInfo.getSomeDate()
                                                .toLocaleString(),
                                Toast.LENGTH_LONG).show();

                    }
                });



        // Custom Bhavesh
        mapFragment.getMap().setInfoWindowAdapter(new InfoWindowAdapter() {

            private final View window = getLayoutInflater().inflate(
                    R.layout.ballonoverlly, null);

            @Override
            public View getInfoWindow(Marker marker) {
                EventInfo eventInfo = eventMarkerMap.get(marker);

                String title = marker.getTitle();
                TextView txtTitle = ((TextView) window
                        .findViewById(R.id.textview_name));
                if (title != null) {
                    // Spannable string allows us to edit the formatting of the
                    // text.
                    SpannableString titleText = new SpannableString(title);
                    titleText.setSpan(new ForegroundColorSpan(Color.RED), 0,
                            titleText.length(), 0);
                    txtTitle.setText(titleText);
                } else {
                    txtTitle.setText("");
                }

                // TextView txtType = ((TextView) window
                // .findViewById(R.id.textview_aboutme));
                // if (eventInfo.getType() != null)
                // txtType.setText(eventInfo.getType());

                return window;
            }

            @Override
            public View getInfoContents(Marker marker) {
                // this method is not called if getInfoWindow(Marker) does not
                // return null
                return null;
            }
        });
    }

}

XML文件:

xml file :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RlMain"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >


    <LinearLayout
        android:id="@+id/imageview_comment"
        android:layout_width="150dp"
        android:layout_height="62dp"
        android:background="@drawable/map_comment_back"
        android:gravity="center_vertical"
        android:orientation="vertical"
        android:scaleType="fitXY"
        android:visibility="visible" >

        <TextView
            android:id="@+id/textview_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:text="Bhavesh Patadiya"
            android:textColor="#FFFFFF"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/textview_aboutme"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:maxLines="2"
            android:text="How&apos;s Going?"
            android:textColor="#FFFFFF"
            android:textStyle="normal" />
    </LinearLayout>
</LinearLayout>

下面是我所得到的屏幕截图:

Below is the Screen Shot of What I am getting :

现在,我想有我的自定义信息窗口的标记,而不是顶部的右侧。

Now , I want to have my custom InfoWindow to the Right Side of the Marker instead of Top.

所有的帮助都是鸭preciated。

All Helps are Appreciated.

在此先感谢。

推荐答案

编辑2:

从谷歌地图Android的API V2 <一个九月更新(V12或65年2月3日)启动href="https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/model/MarkerOptions#infoWindowAnchor%28float,%20float%29"相对=nofollow> MarkerOptions.infoWindowAnchor 加入。有相当多的新功能,所以请发行说明了。

Starting from September update (v12 or 3.2.65) of the Google Maps Android API v2 MarkerOptions.infoWindowAnchor was added. There are quite a few new functions, so check release notes too.

修改3:

很遗憾这除了不能解决您的问题呢。新增新问题了解这一点。

Unfortunatelly this addition doesn't solve your problem yet. Added new issue for that.

这是目前不可能。

试图解决它通过将一个查看 MapFragment 可以是一个很好的解决方案,如果用户是不允许到移动地图。如果他们可以,你会使用两种推屠春风 onCameraChange 或轮询处理程序时,看到一些不好的滞后上重新定位 map.getCameraPosition()

Trying to work around it by putting a View over MapFragment can be a good solution if users are not allowed to move the map. If they can, you will see some bad lags on repositioning when using either "push techonology" onCameraChange or polling with Handler and map.getCameraPosition().

同样的问题,如果您尝试使用额外的标记与透明的图标以显示可见被点击时的信息窗口,但它会更有趣地看到它实际上执行。

Same problems if you try to use additional marker with transparent icon to show info window on when the visible is clicked, but it would be more fun to see it actually implemented.

如果您现在可以生活在没有信息窗口,在右边的,我会建议主演的这个功能已经要求并等待。

If you can live without info window on the right for now, I would suggest starring this feature already requested and waiting.

编辑:

截至3.1.36(转7)的API第2版,您可以更改标记的图标。这意味着你可以做两个图标:一个正常的,另一个看起来你有一个信息窗口右侧开。禁用打开默认的信息窗口,而是用这可能为你工作。

As of 3.1.36 (rev. 7) of the API v2 you can change the icon of marker. This means you can make two icons: one normal, and another that looks like you have an info window open on the right. Disabling opening default info window and using this instead might work for you.

这篇关于Android的谷歌地图API V2:打开自定义信息窗口上标记的右侧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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