【发布时间】:2014-02-19 14:37:11
【问题描述】:
你好 stackoferflow 用户。
我正在开发安卓应用,这个应用实现Google Play Service
我已经获得了我的位置,并在我的地图上设置了一个图钉和一个圆圈。
我想要实现的是每当我移动到某个地方时,圆圈也会移动并将我的位置作为中心位置。
我的问题是:
如何每 2-5 秒更新一次我的当前位置,圆圈也会移动到我的新当前位置
如何将我的圆圈区域设置为标记要放置的区域,这样如果标记不在我的圆圈区域内,它就不会显示在地图上。
谢谢
这是我用于地图的代码:
mMap.setMyLocationEnabled(true);
mMap.getUiSettings().setCompassEnabled(true);
mMap.getUiSettings().setMyLocationButtonEnabled(true);
mMap.getUiSettings().setRotateGesturesEnabled(true);
locationManager = (LocationManager)getSystemService(LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
// Creating a criteria object to retrieve provider
Criteria criteria = new Criteria();
// Getting the name of the best provider
String provider = locationManager.getBestProvider(criteria, true);
// Getting Current Location
Location location = locationManager.getLastKnownLocation(provider);
mMap.setInfoWindowAdapter(new InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker arg0) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
View v = getLayoutInflater().inflate(R.layout.marker, null);
TextView title= (TextView) v.findViewById(R.id.title);
TextView info= (TextView) v.findViewById(R.id.info);
title.setText(marker.getTitle().toString());
info.setText(marker.getSnippet().toString());
return v;
}
});
if(location != null){
double latitude = location.getLatitude();
double longitude = location.getLongitude();
myPosition = new LatLng(latitude, longitude);
CameraUpdate center = CameraUpdateFactory.newLatLngZoom(myPosition, 15);
mMap.moveCamera(center);
mMap.addMarker(new MarkerOptions()
.position(myPosition)
.alpha(0.8f)
.anchor(0.0f, 1.0f)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.blue_pin))
.title("Your position :\n ")
.snippet(latitude + " and " + longitude));
CircleOptions circleOptions = new CircleOptions()
.center(myPosition) //set center
.radius(rad) //set radius in meters
.fillColor(0x402092fd) //default
.strokeColor(Color.LTGRAY)
.strokeWidth(5);
circle = mMap.addCircle(circleOptions);
CameraPosition cameraPosition = CameraPosition.builder()
.target(myPosition)
.zoom(15)
.bearing(90)
.build();
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition),2000, null);
}
谢谢你=)
【问题讨论】:
-
你有另一个例子@ask4solutions 吗?我不知道如何用我的代码实现它。我的意思是我尝试了它,但它似乎不起作用,而且我没有使用 mapView。
标签: android google-maps google-maps-api-3 location geometry