简体   繁体   English

如何在Android Google Maps V2中配置位置按钮

[英]How to configure the location button in android google maps v2

I want to configure the current location button in android google maps v2 but i have no idea how to. 我想在android Google Maps v2中配置当前位置按钮,但是我不知道该怎么做。 It would be helpful as well if you could tell me how to configure a custom overlay button over the map fragment. 如果您能告诉我如何在地图片段上配置自定义叠加按钮,那也会有所帮助。 I just want this button to point to my custom location which i will provide using geo coord instead of pointing to current location 我只希望此按钮指向我的自定义位置,我将使用地理坐标来提供该位置,而不是指向当前位置

Here is a facsimile of a button overlay on map that almost matches the google map buttons. 这是地图上与Google地图按钮几乎匹配的按钮叠加层的传真。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="fill_parent" >

    <fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        class="com.google.android.gms.maps.SupportMapFragment" />

    <Button
        android:id="@+id/btnGPS"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:background="@drawable/mapbutton"
        android:paddingLeft="14dp"
        android:paddingRight="14dp"
        android:text="@string/btnGPS"
        android:textColor="@color/black"
        android:visibility="gone" />

</RelativeLayout>

drawable mapbutton.xml 可绘制的mapbutton.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <corners android:radius="2dp" />

    <stroke
        android:width="1dp"
        android:color="#CC444444" />

    <solid android:color="#88FFFFFF" />

</shape>

Then like any other button you wire up an onClick() event. 然后,像其他任何按钮一样,连接一个onClick()事件。 Then in the onClick() for your button you move the map. 然后在按钮的onClick()中移动地图。 //lat,lon are where your moving the map to. // lat,lon是您将地图移至的位置。

mMap.moveCamera(CameraUpdateFactory
                    .newLatLng(lat,lon));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM