gpt4 book ai didi

java - 将自定义标记添加到 Android 中的 Google map

转载 作者:行者123 更新时间:2023-12-01 16:31:15 24 4
gpt4 key购买 nike

我有一个用java制作的带有Google Maps Activity 的Android应用程序,我想用一个新的标记替换“默认的悉尼”市场,其中带有我通过参数给出的LatLng,但我不知道如何做。我已经尝试过这个=>

public class MapsActivity2 extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;
private double latitud;
private double longitud;
private LatLng ubicacion;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps2);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}


@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;

// Add a marker in Sydney and move the camera
LatLng sydney = ubicacion;
mMap.addMarker(new MarkerOptions().position(sydney).title("Ubicacion Gasto"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}

public void setearUbicacion(double lat, double longi){
ubicacion = new LatLng(lat, longi);
}
}

但“ubicacion”变量无论如何都设置为 null。我不想更改标记的样式,我想通过参数为 onMapReady 方法提供 LatLng,而不是像所有示例所示直接在类上设置它。

提前致谢!

最佳答案

市场?或标记?如果标记你可以尝试这个代码

map.addMarker(new MarkerOptions()
.position(new LatLng(latitude, longitude))
.title("Title")
.snippet("Snippet")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.my_icon)));

只需添加.icon(BitmapDescriptorFactory.fromResource(R.drawable.my_icon))

或更改默认标记的颜色.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))

关于java - 将自定义标记添加到 Android 中的 Google map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62034212/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com