Java Code Examples for org.osmdroid.api.IMapController#setCenter()

The following examples show how to use org.osmdroid.api.IMapController#setCenter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CreatePoiFragment.java    From AndroidApp with Mozilla Public License 2.0 6 votes vote down vote up
private void mapSetup() {
    map = (MapView) getActivity().findViewById(R.id.createPoiMap);

    //important! set your user agent to prevent getting banned from the osm servers
    Configuration.getInstance().load(getActivity(), PreferenceManager.getDefaultSharedPreferences(getActivity()));

    map.setTileSource(TileSourceFactory.MAPNIK);
    map.setTilesScaledToDpi(true);

    // add multi-touch capability
    map.setMultiTouchControls(true);

    // add compass to map
    CompassOverlay compassOverlay = new CompassOverlay(getActivity(), new InternalCompassOrientationProvider(getActivity()), map);
    compassOverlay.enableCompass();
    map.getOverlays().add(compassOverlay);

    // get map controller
    IMapController controller = map.getController();

    GeoPoint position = new GeoPoint(latitude, longitude);
    controller.setCenter(position);
    controller.setZoom(18);
    MapUtils.addMarker(getActivity(), map, latitude, longitude);
}
 
Example 2
Source File: PoiListFragment.java    From AndroidApp with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Show marker of POI on map preview, on {@link RecyclerView} long press
 *
 * @param element POI to  display
 */
private void openMapPreview(Element element) {
    if (map == null) {
        //important! set your user agent to prevent getting banned from the osm servers
        Configuration.getInstance().load(getActivity(), PreferenceManager.getDefaultSharedPreferences(getActivity()));

        map = getActivity().findViewById(R.id.mapPoiList);
        map.setTileSource(TileSourceFactory.MAPNIK);
        map.setTilesScaledToDpi(true);

        // add multi-touch capability
        map.setMultiTouchControls(true);

        // add compass to map
        CompassOverlay compassOverlay = new CompassOverlay(getActivity(), new InternalCompassOrientationProvider(getActivity()), map);
        compassOverlay.enableCompass();
        map.getOverlays().add(compassOverlay);
    }
    // get map controller
    IMapController controller = map.getController();
    GeoPoint position = new GeoPoint(element.lat, element.lon);
    controller.setCenter(position);
    controller.setZoom(18);

    MapUtils.addMarker(getActivity(), map, element);
}
 
Example 3
Source File: PoiDetailsFragment.java    From AndroidApp with Mozilla Public License 2.0 6 votes vote down vote up
private void setupMapPreview(double lat, double lon, String markerTitle) {
    //important! set your user agent to prevent getting banned from the osm servers
    Configuration.getInstance().load(getDialog().getContext(), PreferenceManager.getDefaultSharedPreferences(getDialog().getContext()));

    map = (MapView) getDialog().findViewById(R.id.poiDialogMap);
    map.setTileSource(TileSourceFactory.MAPNIK);
    map.setTilesScaledToDpi(true);
    map.setMultiTouchControls(true);

    // add compass to map
    CompassOverlay compassOverlay = new CompassOverlay(getDialog().getContext(), new InternalCompassOrientationProvider(getDialog().getContext()), map);
    compassOverlay.enableCompass();
    map.getOverlays().add(compassOverlay);

    // get map controller
    IMapController controller = map.getController();
    GeoPoint position = new GeoPoint(lat, lon);
    controller.setCenter(position);
    controller.setZoom(18);

    MapUtils.addMarker(getActivity(), map, lat, lon, markerTitle);
}
 
Example 4
Source File: EditPoiFragment.java    From AndroidApp with Mozilla Public License 2.0 6 votes vote down vote up
private void mapSetup() {
    map = getActivity().findViewById(R.id.createPoiMap);
    //important! set your user agent to prevent getting banned from the osm servers
    Configuration.getInstance().load(getActivity(), PreferenceManager.getDefaultSharedPreferences(getActivity()));
    map.setTileSource(TileSourceFactory.MAPNIK);
    map.setTilesScaledToDpi(true);
    map.setMultiTouchControls(true);

    CompassOverlay compassOverlay = new CompassOverlay(getActivity(), new InternalCompassOrientationProvider(getActivity()), map);
    compassOverlay.enableCompass();
    map.getOverlays().add(compassOverlay);

    IMapController controller = map.getController();
    GeoPoint position = new GeoPoint(POI.getLatitude(), POI.getLongitude());
    controller.setCenter(position);
    controller.setZoom(18);

    MapUtils.addMarker(getActivity(), map, POI.getLatitude(), POI.getLongitude());
}
 
Example 5
Source File: PoiListFragment.java    From AndroidApp with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Show all markers of the POIs on the map preview
 *
 * @param elements List of POIs to display
 */
private void setupMapMarkers(List<Element> elements) {
    //important! set your user agent to prevent getting banned from the osm servers
    Configuration.getInstance().load(getActivity(), PreferenceManager.getDefaultSharedPreferences(getActivity()));

    //clear existing markers
    if (map != null)
        map.getOverlays().clear();
    map = getActivity().findViewById(R.id.mapPoiList);
    map.setTileSource(TileSourceFactory.MAPNIK);
    map.setTilesScaledToDpi(true);
    map.setMultiTouchControls(true);

    // add compass to map
    CompassOverlay compassOverlay = new CompassOverlay(getActivity(), new InternalCompassOrientationProvider(getActivity()), map);
    compassOverlay.enableCompass();
    map.getOverlays().add(compassOverlay);

    // get map controller
    IMapController controller = map.getController();

    for (Element element : elements)
        MapUtils.addMarker(getActivity(), map, element);

    if (elements.size() > 0) {
        GeoPoint position = new GeoPoint(elements.get(0).lat, elements.get(0).lon);
        controller.setCenter(position);
        controller.setZoom(14);
    }
    setupMyLocation();
}
 
Example 6
Source File: MapFragment.java    From wikijourney_app with Apache License 2.0 5 votes vote down vote up
private void drawCurrentLocation(Location location) {

        IMapController mapController = map.getController();

        // This starts the map at the desired point
        userLocation = new GeoPoint(location);
        if (!isUserLocatedOnce) {
            mapController.setCenter(userLocation);
        }

        // Now we add a marker using osmBonusPack
        userLocationMarker.setPosition(userLocation);
        userLocationMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
        map.getOverlays().add(userLocationMarker);

        // And we have to use this to refresh the map
        // map.invalidate();

        // We can change some properties of the marker (don't forget to refresh the map !!)
        userLocationMarker.setInfoWindow(new CustomInfoWindow(map));
        Drawable icon = null;
        if (getActivity() != null) {
            icon = ContextCompat.getDrawable(getActivity(), eu.wikijourney.wikijourney.R.drawable.ic_place);
        }
        try {
            userLocationMarker.setIcon(icon);
            userLocationMarker.setTitle(getString(eu.wikijourney.wikijourney.R.string.you_are_here));
            map.invalidate();
        } catch (Exception e) {
            Log.e(LOG_ERROR, "drawCurrentLocation: " + e.getMessage(), e);
            e.printStackTrace();
        }
    }
 
Example 7
Source File: WeathForceActivity.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_starter_mapview);

    Intent intent = getIntent();
    //if (intent)
    final double lat1 = 25.633;
    final double long1 = 71.094;

    //super important. Many tile servers, including open street maps, will BAN applications by user
    //agent. Do not use the sample application's user agent for your app! Use your own setting, such
    //as the app id.
    Configuration.getInstance().setUserAgentValue(getPackageName());

    mMapView = findViewById(R.id.mapview);
    mMapView.setTileSource(TileSourceFactory.MAPNIK);


    mCompassOverlay = new CompassOverlay(this, new InternalCompassOrientationProvider(this),
            mMapView);
    mCompassOverlay.enableCompass();
    mMapView.getOverlays().add(this.mCompassOverlay);

    addOverlays();

    GeoPoint startPoint = new GeoPoint(lat1, long1);
    IMapController mapController = mMapView.getController();
    mapController.setZoom(9);
    mapController.setCenter(startPoint);
    Marker startMarker = new Marker(mMapView);
    startMarker.setPosition(startPoint);
    startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
    mMapView.getOverlays().add(startMarker);


    mMapView.invalidate();

}
 
Example 8
Source File: MapActivity.java    From ActivityDiary with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Context ctx = getApplicationContext();
    Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));

    LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View contentView = inflater.inflate(R.layout.activity_map, null, false);

    setContent(contentView);

    noMap = (TextView) findViewById(R.id.noMap);

    map = (MapView) findViewById(R.id.map);
    map.setTileSource(TileSourceFactory.MAPNIK);
    map.setTilesScaledToDpi(true);
    map.setBuiltInZoomControls(true);
    map.setMultiTouchControls(true);

    IMapController mapController = map.getController();
    mapController.setZoom(14.0);
    GeoPoint startPoint = new GeoPoint(LocationHelper.helper.getCurrentLocation());
    mapController.setCenter(startPoint);

    CopyrightOverlay copyrightOverlay = new CopyrightOverlay(this);
    copyrightOverlay.setTextSize(10);
    map.getOverlays().add(copyrightOverlay);

    ScaleBarOverlay scaleBarOverlay = new ScaleBarOverlay(map);
    map.getOverlays().add(scaleBarOverlay);
    // Scale bar tries to draw as 1-inch, so to put it in the top center, set x offset to
    // half screen width, minus half an inch.
    scaleBarOverlay.setScaleBarOffset(
            (int) (getResources().getDisplayMetrics().widthPixels / 2 - getResources()
                    .getDisplayMetrics().xdpi / 2), 10);

    getLoaderManager().initLoader(LOADER_ID_INIT, null, this);

    mDrawerToggle.setDrawerIndicatorEnabled(false);
}