我有一个位置活动类,其中有一个由数据库值组成的微调器。我单击其中一个值,查询数据库并返回坐标。我知道我得到了正确的坐标,因为我已经在应用程序中测试了查询。
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, final int i, long id) {
switch (i) {
case 0:
//remove marker
break;
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
getSuggestedLocation(i);
//Antrim marker
break;
//Armagh marker
//Belfast marker
//Derry marker
//Down marker
//Fermanagh marker
//Tyrone marker
}
}
我想更新我的地图,以便在刚刚选择的微调器坐标选项上放置一个标记。
private void inflateMapFragment(){
MapFragment fragment = MapFragment.newInstance();
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.map_container, new MapFragment());
ft.commit();
}
private void buildLocationCallBack() {
locationCallback = new LocationCallback()
{
@Override
public void onLocationResult(LocationResult locationResult)
{
for(android.location.Location location:locationResult.getLocations())
currentLocation = (String.valueOf(location.getLatitude())
+ "/"
+ String.valueOf(location.getLongitude()));
}
};
}
private void buildLocationRequest()
{
locationRequest = new LocationRequest();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setInterval(5000);
locationRequest.setFastestInterval(3000);
locationRequest.setSmallestDisplacement(10);
值得注意的是,我确实手动在onLocationResult方法中设置了currentLocation。然而,如果选择了一个选项,我想将值从我的数据库传递到那个currentLocation,但我不知道如何从切换到必要的方法中获得结果。请帮帮我的脑袋炸了哈哈,我一点也不喜欢安卓工作室
您可以调用此函数,只需全局声明您的GoogleMap即可。
yourGoogleMap.clear();
LatLng latlng = new LatLng(YOUR_LATITUDE, YOUR_LONGITUDE);
MarkerOptions options = new MarkerOptions()
.position(latlng)
.title(YOUR_TITLE);
yourGoogleMap.addMarker(options);
yourGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, 16.0f));