Сначала вам нужно просмотреть карту:
MapView mapView = (MapView) findViewById(R.id.mapView);
Отображение других пользователей:
List<GeoPoint> otherUsers = .... from your service
for(GeoPoint user: otherUsers )
{
mapView .addOverlay(new MapOverlay(user);
}
Центрирование карты вокруг пользователя:
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
Location l = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
//or if you want to use gps l = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
//you may want to use a different manner of getting the location since this may be out of date. see http://developer.android.com/reference/android/location/LocationListener.html for live data
point = new GeoPoint((int)(l.getLatitude()*1e6),(int)(l.getLongitude()*1e6));
mc.animateTo(point);
mapView.setBuiltInZoomControls(true);
mapView.invalidate();
Класс оверлеянеобходимо показать другим пользователям:
public class MapOverlay extends Overlay {
private GeoPoint data;
public MapLineOverlay( GeoPoint item) {
data = item;
}
/* (non-Javadoc)
* @see com.google.android.maps.Overlay#draw(android.graphics.Canvas, com.google.android.maps.MapView, boolean, long)
*/
@Override
public boolean draw(Canvas canvas, MapView mapView, boolean shadow,long when) {
Projection projection = mapView.getProjection();
if (shadow == false) {
Paint paint = new Paint();
paint.setAntiAlias(true);
Point point = new Point();
projection.toPixels(data, point);
paint.setColor(color);
paint.setStrokeWidth(4);
canvas.drawPoint((float) point.x, (float) point.y, , paint);
}
return super.draw(canvas, mapView, shadow, when);
}
/* (non-Javadoc)
* @see com.google.android.maps.Overlay#draw(android.graphics.Canvas, com.google.android.maps.MapView, boolean)
*/
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
super.draw(canvas, mapView, shadow);
}
}