我可以在Android地图中更改我的位置按钮吗
我们在谷歌地图中有一个我的位置图标,如我可以在Android地图中更改我的位置按钮吗,android,google-maps,google-maps-android-api-2,google-maps-api-2,Android,Google Maps,Google Maps Android Api 2,Google Maps Api 2,我们在谷歌地图中有一个我的位置图标,如 我想用我想要的图标更改此图标按钮。是否有任何方法在谷歌地图中替换此图标。我如何在Android中做到这一点 由于问题不清楚,因此我将补充更多信息。在中,您可以在第节中看到根据您的位置获取方向第2点中显示了图标 修复您的位置->了解位置符号的下方部分也解释了这些图标 正如您所看到的,它不是标记,而是一个位置按钮,正如我所写的,因此我的问题是如何将该图标(位置按钮)更改为所需的图标。 查看此图标按钮也显示在谷歌地图图标图片中 是的,你可以 我在我的地图片段中解
我想用我想要的图标更改此图标按钮。是否有任何方法在谷歌地图中替换此图标。我如何在Android中做到这一点 由于问题不清楚,因此我将补充更多信息。在中,您可以在第节中看到根据您的位置获取方向第2点中显示了图标 修复您的位置->了解位置符号的下方部分也解释了这些图标 正如您所看到的,它不是标记,而是一个位置按钮,正如我所写的,因此我的问题是如何将该图标(位置按钮)更改为所需的图标。 查看此图标按钮也显示在谷歌地图图标图片中 是的,你可以 我在我的地图片段中解决了这个问题,使用下面的代码将我的位置按钮重新定位到视图的右下角,这是我的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);
}
}
}
下面是片段的布局:-
<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>
我希望这能解决你的问题。谢谢。我知道这是一个迟到的回复,但这段代码对我来说很有用
ImageView btnMyLocation = (ImageView) ((View) mapFragment.getView().findViewById(1).getParent()).findViewById(2);
btnMyLocation.setImageResource(R.mipmap.ic_location_circle);
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams)
btnMyLocation.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);
快乐的编码 我正在使用的东西
ImageView btnMyLocation = (ImageView) ((View) mapFragment.getView().findViewById(Integer.parseInt("1")).getParent()).findViewById(Integer.parseInt("2"));
btnMyLocation.setImageResource(R.drawable.ic_current_location);
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams)
btnMyLocation.getLayoutParams();
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
layoutParams.setMargins(0, 0, 30, 30);
btnMyLocation.setLayoutParams(layoutParams);
希望这会有帮助……可能会帮助您更改您的ICON,无论是谁在标记它,如果他们认为这太简单,请提供答案,然后标记down@SonuRaj你告诉我的是改变myLocation图标,但我想改变位于地图右上方的按钮的形状。这个答案有你需要的:它与签名的apk一起工作吗?它在调试模式下对我有效,但在发布模式下无效。您在发布模式下面临的确切问题是什么?我认为,在MAPAPIv2中,发布版本和调试版本之间唯一的变化是您在这里注册的密钥code.google.com/API/console如果调试正常,而最终版本不正常,那么这是唯一需要的变化。因此,我建议您仔细检查发布密钥库的哈希代码,并确保它在GoogleAPI控制台上正确输入@完成了吗。问题是,我们使用了整数值1。用Integer.parseInt(“1”)替换它,它成功了。我很高兴,你做到了。但是上面给出的代码本身使用Integer.parseInt(“1”)@Seema为什么要硬编码然后解析整数值?除此之外,您应该尝试解释代码正在做什么来帮助OP理解它。