android - 我可以在 Android map 中更改我的位置按钮吗

标签 android google-maps google-maps-android-api-2 google-maps-api-2

我们在谷歌地图中有一个我的位置图标
My Location Icon 我想用我想要的图标更改此图标按钮,有什么方法可以替换 Google map 中的此图标。我怎样才能在 Android 中做到这一点。

由于问题不清楚,所以我添加了附加信息。在 https://support.google.com/maps/answer/3093609?hl=en您可以在第 2 点的 Get directions based on your location 部分看到该图标已显示 enter image description here

修复您的位置-> 了解位置符号 中的部分也解释了这些图标。

如您所见,它不是标记,而是我写的位置按钮 所以我的问题是如何将该图标(位置按钮)更改为我想要的图标。

看到这个图标按钮也显示在谷歌地图图标图片中 enter image description here

最佳答案

是的,你可以,

我通过使用下面的代码将我的位置按钮重新定位到 View 的右下角解决了我的 map fragment 中的这个问题,这是我的 MapsActivity.java :-

import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private GoogleMap mMap;
    View mapView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_map);
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapView = mapFragment.getView();
        mapFragment.getMapAsync(this);
            }

    /**
     * Manipulates the map once available.
     * This callback is triggered when the map is ready to be used.
     * This is where we can add markers or lines, add listeners or move the camera. In this case,
     * we just add a marker near Sydney, Australia.
     * If Google Play services is not installed on the device, the user will be prompted to install
     * it inside the SupportMapFragment. This method will only be triggered once the user has
     * installed Google Play services and returned to the app.
     */
    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;
        mMap.setMyLocationEnabled(true);

        // Add a marker in Sydney and move the camera
        LatLng sydney = new LatLng(-34, 151);
        mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));

        if (mapView != null &&
                mapView.findViewById(Integer.parseInt("1")) != null) {
            // Get the button view
            View locationButton = ((View) mapView.findViewById(Integer.parseInt("1")).getParent()).findViewById(Integer.parseInt("2"));
            // and next place it, on bottom right (as Google Maps app)
            RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams)
                    locationButton.getLayoutParams();
            // position on right bottom
            layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0);
            layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
            layoutParams.setMargins(0, 0, 30, 30);
        }

    }
}

这是 fragment 的布局:-

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.infogird.www.location_button_reposition.MapFragment">

    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:map="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
</FrameLayout>

希望这能解决您的问题。谢谢。

关于android - 我可以在 Android map 中更改我的位置按钮吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27794221/

相关文章:

java - Android使用smtp发送邮件到gmail

javascript - 在多边形中添加一些区域 [JavaScript::Google Map API v3]

java - 根据用户输入在 Google map V2 上绘制圆圈

java - 使用 Endless 适配器的 ListView

Android map - 限制在 180 度

android - Xamarin Forms - Webview 未显示在我的 StackLayout 中

java - Google 地理编码 API 返回非法访问错误

json - Google Places Api 排名=距离 不起作用

android - Fused location provider 似乎没有按照间隔集更新坐标

java - 调整 'Google maps V2' 以占据屏幕的一半而不是整个屏幕