android的谷歌地图我的位置自定义按钮 [英] Google map for android my location custom button
本文介绍了android的谷歌地图我的位置自定义按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何更改谷歌地图我的位置默认按钮?我设置了我的位置启用和地图绘制标准图像来查找位置,是否可以更改默认图像?
How can I change google map my location default button? I set my location enable and map draw standard image to find location, is it possible to change default image?
推荐答案
自定义按钮见下面的xml文件:
See below xml file to custom button:
<?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="match_parent"
android:orientation="vertical" >
<fragment
android:id="@+id/maps"
android:name="pl.mg6.android.maps.extensions.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp" >
<ImageView
android:id="@+id/imgMyLocation"
android:layout_width="40dp"
android:layout_height="40dp"
android:scaleType="fitXY"
android:src="@drawable/track_my_location" />
</LinearLayout>
</RelativeLayout>
然后在java类中,声明您的位置按钮:
Then in java class, declare your location button:
private ImageView imgMyLocation;
imgMyLocation = (ImageView) findViewById(R.id.imgMyLocation);
点击事件:
imgMyLocation.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
getMyLocation();
}
获取位置方法,只需传递您当前的纬度和经度即可.
Get Location Method, in that just pass your current latitude and longitude.
private void getMyLocation() {
LatLng latLng = new LatLng(Double.parseDouble(getLatitude()), Double.parseDouble(getLongitude()));
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 18);
googleMap.animateCamera(cameraUpdate);
}
});
这篇关于android的谷歌地图我的位置自定义按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文