我可以在Android地图中更改我的位置按钮吗? [英] Can I Change My Location Button in Android Maps
问题描述
我们在Google地图中有一个位置图标,例如
我想用我想要的图标更改此图标按钮有什么方法可以在Google地图中替换此图标。我怎么能在Android中做到这一点。
由于问题不清楚,所以我添加了附加信息。在 https://support.google.com/maps/answer/3093609?hl=您可以在根据您的位置获取路线部分的第2点中看到图标修复您的位置 - >了解位置符号中的部分也解释了这些内容图标。 正如您所看到的,它不是标记,它是位置按钮,因为我写了所以我的问题是如何将该图标(位置按钮)更改为我想要的图标。 查看此图标按钮也显示在Google地图图标中pic 当然可以, 我通过使用下面的代码将我的位置按钮重新定位到视图的右下角来解决此问题,这里是我的MapsActivity.java: - 是片段的布局: - 我希望这能解决您的问题。谢谢。 We have a my location Icon in google maps like As the Question was unclear so i am adding Additional information. In https://support.google.com/maps/answer/3093609?hl=en you can see in section Get directions based on your location in point number 2 the icon had been shown The Section just below in Fix your location-> Understand Location Symbols also explains these icons. As you can see it is not the marker it's a location button as i had written So my question is how can i change that icon (location button) to my desired icon. See this icon button is also shown in the google maps icon pic
Yes you can, I solved this problem in my map fragment by re positioning my location button to the right bottom corner of view using code below, here is my MapsActivity.java :- And here is layout of fragment :- I hope, this will solve your problem. Thanks. 这篇关于我可以在Android地图中更改我的位置按钮吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
import android.support.v4.app.FragmentActivity;
导入android.os.Bundle;
导入android.view.View;
导入android.view.ViewGroup;
导入android.widget.RelativeLayout;
import com.google.android.gms.maps.CameraUpdateFactory;
导入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;
导入com.google.android.gms.maps.model.MarkerOptions;
公共类MapsActivity扩展FragmentActivity实现OnMapReadyCallback {
私有GoogleMap mMap;
查看地图查看;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_map);
//获取SupportMapFragment并在地图准备好使用时得到通知。
SupportMapFragment mapFragment =(SupportMapFragment)getSupportFragmentManager()
.findFragmentById(R.id.map);
mapView = mapFragment.getView();
mapFragment.getMapAsync(this);
}
/ **
*操作一次可用的地图。
*当地图准备好使用时,会触发此回调。
*这是我们可以添加标记或线条,添加听众或移动相机的位置。在这种情况下,
*我们只在澳大利亚悉尼附近添加一个标记。
*如果设备上未安装Google Play服务,系统会提示用户在SupportMapFragment中安装
* it。只有当用户安装了
* Google Play服务并返回到应用时,才会触发此方法。
* /
@Override
public void onMapReady(GoogleMap googleMap){
mMap = googleMap;
mMap.setMyLocationEnabled(true);
//在悉尼添加一个标记并移动相机
LatLng sydney = new LatLng(-34,151);
mMap.addMarker(new MarkerOptions()。position(sydney).title(Marker in Sydney));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
如果(MapView类= NULL&安培;!&安培;!
mapView.findViewById(的Integer.parseInt( 1))= NULL){
//获取按钮视图
查看locationButton =((查看)mapView.findViewById(的Integer.parseInt( 1))的getParent()。)findViewById(的Integer.parseInt( 2));
//和未来的地方是,在右下角(如谷歌地图应用)
RelativeLayout.LayoutParams的LayoutParams =(RelativeLayout.LayoutParams)
locationButton.getLayoutParams();
//右下方的位置
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP,0);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM,RelativeLayout.TRUE);
layoutParams.setMargins(0,0,30,30);
}
}
}
< FrameLayout xmlns:android =http://schemas.android.com/apk/ RES / Android的
的xmlns:工具= http://schemas.android.com/tools
的android:layout_width = match_parent
机器人:layout_height = match_parent
工具: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>
I want to change this icon button with my desired Icon is there any way to replace this icon in the Google Maps. How can i do that in Android.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);
}
}
}
<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>