Помогите пожалуйста не могу соединить userLocationObjectListener,Sesion.searchListener,DrivingSesion.DrivingRouteListener чтоб набирал и поехал
public class MainActivity extends AppCompatActivity implements UserLocationObjectListener, Session.SearchListener, CameraListener, DrivingSession.DrivingRouteListener, MainActivity1 {
//не трогать
private final String MAPKIT_API_KEY = "df1af944-24ea-46da-bc86-7f6ad132af11";
private final Point TARGET_LOCATION = new Point(59.945933, 97.820);
private MapView mapView;
private static final int PERMISSIONS_REQUEST_FINE_LOCATION = 10;
private UserLocationLayer userLocationLayer;
//не трогать
private final int RESULT_NUMBER_LIMIT = 5;
private EditText searchEdit;
private SearchManager searchManager;
private Session searchSession;
private void submitQuery(String query) {
searchSession = searchManager.submit(
query,
VisibleRegionUtils.toPolygon(mapView.getMap().getVisibleRegion()),
new SearchOptions(),
this);
}
private SuggestSession suggestSession;
private ListView suggestResultView;
private ArrayAdapter resultAdapter;
private List<String> suggestResult;
private final Point CENTER = new Point(55.75, 37.62);
private final double BOX_SIZE = 0.2;
private final BoundingBox BOUNDING_BOX = new BoundingBox(
new Point(CENTER.getLatitude() - BOX_SIZE, CENTER.getLongitude() - BOX_SIZE),
new Point(CENTER.getLatitude() + BOX_SIZE, CENTER.getLongitude() + BOX_SIZE));
private final SuggestOptions SEARCH_OPTIONS = new SuggestOptions().setSuggestTypes(
SuggestType.GEO.value |
SuggestType.BIZ.value |
SuggestType.TRANSIT.value);
private final Point ROUTE_START_LOCATION = new Point(59.959194, 30.407094);
private final Point ROUTE_END_LOCATION = new Point(55.733330, 37.587649);
private final Point SCREEN_CENTER = new Point(
(ROUTE_START_LOCATION.getLatitude() + ROUTE_END_LOCATION.getLatitude()) / 2,
(ROUTE_START_LOCATION.getLongitude() + ROUTE_END_LOCATION.getLongitude()) / 2);
private MapObjectCollection mapObjects;
private DrivingRouter drivingRouter;
private DrivingSession drivingSession;
@Override
protected void onCreate(Bundle savedInstanceState) {
//не трогать
MapKitFactory.setApiKey(MAPKIT_API_KEY);
MapKitFactory.initialize(this);
//не трогать
SearchFactory.initialize(this);
DirectionsFactory.initialize(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//не трогать
mapView = (MapView) findViewById(R.id.mapview);
mapView.getMap().move(new CameraPosition(TARGET_LOCATION, 0.0f, 0.0f, 0.0f), new Animation(Animation.Type.SMOOTH, 0), null);
MapKit mapKit = MapKitFactory.getInstance();
mapKit.resetLocationManagerToDefault();
userLocationLayer = mapKit.createUserLocationLayer(mapView.getMapWindow());
userLocationLayer.setVisible(true);
userLocationLayer.setHeadingEnabled(true);
userLocationLayer.setObjectListener(this);
requestLocationPermission();
//не трогать
searchManager = SearchFactory.getInstance().createSearchManager(SearchManagerType.COMBINED);
mapView = findViewById(R.id.mapview);
mapView.getMap().addCameraListener(this);
searchEdit = findViewById(R.id.search_edit);
searchEdit.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
submitQuery(searchEdit.getText().toString());
}
return false;
}
});
submitQuery(searchEdit.getText().toString());
suggestSession = searchManager.createSuggestSession();
suggestResultView = (ListView)findViewById(R.id.suggest_result);
suggestResult = new ArrayList<>();
resultAdapter = new ArrayAdapter(this,
android.R.layout.simple_list_item_2,
android.R.id.text1,
suggestResult);
suggestResultView.setAdapter(resultAdapter);
searchEdit.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
@Override
public void afterTextChanged(Editable editable) {
requestSuggest(editable.toString());
}
});
drivingRouter = DirectionsFactory.getInstance().createDrivingRouter();
mapObjects = mapView.getMap().getMapObjects().addCollection();
submitRequest();
}
@Override
protected void onStop() {
// Вызов onStop нужно передавать инстансам MapView и MapKit.
mapView.onStop();
MapKitFactory.getInstance().onStop();
super.onStop();
}
@Override
protected void onStart() {
// Вызов onStart нужно передавать инстансам MapView и MapKit.
super.onStart();
MapKitFactory.getInstance().onStart();
mapView.onStart();
}
private void requestLocationPermission() {
if (ContextCompat.checkSelfPermission(this,
"android.permission.ACCESS_FINE_LOCATION")
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{"android.permission.ACCESS_FINE_LOCATION"},
PERMISSIONS_REQUEST_FINE_LOCATION);
}
}
//Вызывается при добавлении объекта слоя. Он вызывается один раз, когда значок местоположения пользователя появляется в первый раз. @Override public void onObjectAdded(@NonNull UserLocationView userLocationView) { userLocationLayer.setAnchor( new PointF((float) (mapView.getWidth() * 0.5), (float) (mapView.getHeight() * 0.5)), new PointF((float) (mapView.getWidth() * 0.5), (float) (mapView.getHeight() * 0.83)));
userLocationView.getArrow().setIcon(ImageProvider.fromResource( //Задает значок со стилем по умолчанию для метки.
this, R.drawable.locicon));
CompositeIcon pinIcon = userLocationView.getPin().useCompositeIcon();
pinIcon.setIcon(
"icon",
ImageProvider.fromResource(this, R.drawable.temka_map_pin_02),
new IconStyle().setAnchor(new PointF(0f, 0f))
.setRotationType(RotationType.ROTATE)
.setZIndex(0f)
.setScale(1f)
);
pinIcon.setIcon(
"pin",
ImageProvider.fromResource(this, R.drawable.search_result),
new IconStyle().setAnchor(new PointF(0.5f, 0.5f))
.setRotationType(RotationType.ROTATE)
.setZIndex(1f)
.setScale(0.5f)
);
userLocationView.getAccuracyCircle().setFillColor(Color.BLUE & 0x99ffffff);
}
//Вызывается при удалении объекта слоя. Он никогда не вызывается для значка местоположения пользователя.
@Override
public void onObjectRemoved(@NonNull UserLocationView userLocationView) {
}
////Вызывается при обновлении объекта слоя. Параметр 'event' может быть одним из производных типов.
@Override
public void onObjectUpdated(@NonNull UserLocationView userLocationView, @NonNull ObjectEvent objectEvent) {
}
@Override
public void onCameraPositionChanged(@NonNull Map map, @NonNull CameraPosition cameraPosition, @NonNull CameraUpdateReason cameraUpdateReason, boolean finished) {
if (finished) {
submitQuery(searchEdit.getText().toString());
}
}
@Override
public void onSearchResponse(@NonNull Response response) {
MapObjectCollection mapObjects = mapView.getMap().getMapObjects();
mapObjects.clear();
for (GeoObjectCollection.Item searchResult : response.getCollection().getChildren()) {
Point resultLocation = searchResult.getObj().getGeometry().get(0).getPoint();
if (resultLocation != null) {mapObjects.addPlacemark(resultLocation, ImageProvider.fromResource(this, R.drawable.search_result));
CameraPosition cameraPosition = new CameraPosition(resultLocation, 14.0f, 0.0f, 0.0f);
mapView.getMap().move(cameraPosition);
return;
}
}
}
@Override
public void onSearchError(@NonNull Error error) {
}
@Override
public void onResponse(@NonNull List<SuggestItem> suggest) {
suggestResult.clear();
for (int i = 0; i < Math.min(RESULT_NUMBER_LIMIT, suggest.size()); i++) {
suggestResult.add(suggest.get(i).getDisplayText());
}
resultAdapter.notifyDataSetChanged();
suggestResultView.setVisibility(View.VISIBLE);
}
@Override
public void onError(@NonNull Error error) {
String errorMessage = getString(R.string.unknown_error_message);
if (error instanceof RemoteError) {
errorMessage = getString(R.string.remote_error_message);
} else if (error instanceof NetworkError) {
errorMessage = getString(R.string.network_error_message);
}
Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT).show();
}
private void requestSuggest(String query) {
suggestResultView.setVisibility(View.INVISIBLE);
suggestSession.suggest(query, BOUNDING_BOX, SEARCH_OPTIONS, (SuggestSession.SuggestListener) this);
}
@Override
public void onPointerCaptureChanged(boolean hasCapture) {
super.onPointerCaptureChanged(hasCapture);
}
@Override
public void onDrivingRoutes(@NonNull List<DrivingRoute> routes) {
}
@Override
public void onDrivingRoutesError(@NonNull Error error) {
}
private void submitRequest() {
DrivingOptions drivingOptions = new DrivingOptions();
VehicleOptions vehicleOptions = new VehicleOptions();
ArrayList<RequestPoint> requestPoints = new ArrayList<>();
requestPoints.add(new RequestPoint(
ROUTE_START_LOCATION,
RequestPointType.WAYPOINT,
null));
requestPoints.add(new RequestPoint(
ROUTE_END_LOCATION,
RequestPointType.WAYPOINT,
null));
drivingSession = drivingRouter.requestRoutes(requestPoints, drivingOptions, vehicleOptions, this);
}