在Android项目中,为什么不能标记从其他类获取纬度和经度的位置
无法在地图上标记位置2,但如果使用位置1替换它,则成功在Android项目中,为什么不能标记从其他类获取纬度和经度的位置,android,google-maps,Android,Google Maps,无法在地图上标记位置2,但如果使用位置1替换它,则成功 public void onMapReady(GoogleMap googleMap) { mMap = googleMap; LatLng LOCATION1 = new LatLng(18.79038, 98.98468); int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permissi
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
LatLng LOCATION1 = new LatLng(18.79038, 98.98468);
int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_CALENDAR);
mMap.setMyLocationEnabled(true);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LOCATION1, 13));
vehicles=query.QueryVhe();
Double lat=vehicles.get(0).getLatitude(); //get latitude.
Double lng=vehicles.get(0).getLongitude();//get Longitude.
//I am sure that lat and lng have already got data here.
//here is a problem that it is fail to mark LOCATION2.
LatLng LOCATION2 = new LatLng(lat, lng);
mMap.addMarker(new MarkerOptions()
.title("Sydney")
.snippet("Chaing Mai.")
.position(LOCATION2));// But if it is successful if LOCATION2 were LOCATION1.
}
}
使用此代码
如果这对你有帮助,请把它做得恰到好处
mMap.addMarker(new MarkerOptions()
.title("My Location")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.myloc))
.anchor(0.0f, 1.0f) // Anchors the marker on the bottom left
.position(new LatLng(lat, lon)))
.setDraggable(true);
如果您不需要锚定或SetDragable,您可以删除它使用此代码
如果这对你有帮助,请把它做得恰到好处
mMap.addMarker(new MarkerOptions()
.title("My Location")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.myloc))
.anchor(0.0f, 1.0f) // Anchors the marker on the bottom left
.position(new LatLng(lat, lon)))
.setDraggable(true);
如果您不需要锚定或可设置标记,您可以将其删除您可以按以下方式添加标记
Marker marker = map.addMarker(new MarkerOptions()
.position(new LatLng(37.7750, 122.4183)) // those are dummy values for lat and long
.icon(BitmapDescriptorFactory.fromResource(R.drawable.location))
.title("My Location on Map")
.snippet("details"));
您可以按以下方式添加标记
Marker marker = map.addMarker(new MarkerOptions()
.position(new LatLng(37.7750, 122.4183)) // those are dummy values for lat and long
.icon(BitmapDescriptorFactory.fromResource(R.drawable.location))
.title("My Location on Map")
.snippet("details"));
通过以下方式获得位置2的(lat,lng)值:Query Query=new Query();列出车辆=新的ArrayList();查询是一个从数据库获取数据的类。从中可以通过以下方式获取位置2的(lat,lng)值:Query Query=new Query();列出车辆=新的ArrayList();查询是从数据库获取数据的类。latlng值不能预定义。。。当marker创建只有时间的新latlng值时,通过使用新latlng(lat,lng),您不能在此处直接使用latlng变量。使用新latlng(lat,lng)也不起作用,只需处理如下常数的数据:lat=37.7750,lng=122.4183。但我确信我的lat和lng已通过调试获得数据。无法预定义latlng值。。。当marker创建只有时间的新latlng值时,通过使用新latlng(lat,lng),您不能在这里直接使用latlng变量。使用新latlng(lat,lng)也不起作用,只需处理如下常量的数据:lat=37.7750,lng=122.4183。但我确信我的lat和lng已通过调试获得数据。