Search in sources :

Example 16 with GeoPoint

use of org.oscim.core.GeoPoint in project PocketMaps by junjunguo.

the class MapActions method initUseCurrentLocationHandler.

/**
 * current location handler: preform actions when current location item is clicked
 */
private void initUseCurrentLocationHandler(final boolean isStartP) {
    int viewID = R.id.map_nav_settings_to_current;
    if (isStartP) {
        viewID = R.id.map_nav_settings_from_current;
    }
    final ViewGroup useCurrentLocal = (ViewGroup) activity.findViewById(viewID);
    useCurrentLocal.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch(event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    setBgColor(useCurrentLocal, R.color.my_primary_light);
                    return true;
                case MotionEvent.ACTION_UP:
                    setBgColor(useCurrentLocal, R.color.my_primary);
                    if (MapActivity.getmCurrentLocation() != null) {
                        GeoPoint newPos = new GeoPoint(MapActivity.getmCurrentLocation().getLatitude(), MapActivity.getmCurrentLocation().getLongitude());
                        if (isStartP) {
                            Destination.getDestination().setStartPoint(newPos);
                            addFromMarker(Destination.getDestination().getStartPoint());
                            fromLocalET.setText(Destination.getDestination().getStartPointToString());
                            navSettingsFromVP.setVisibility(View.INVISIBLE);
                        } else {
                            Destination.getDestination().setEndPoint(newPos);
                            addToMarker(Destination.getDestination().getEndPoint());
                            toLocalET.setText(Destination.getDestination().getEndPointToString());
                            navSettingsToVP.setVisibility(View.INVISIBLE);
                        }
                        boolean showingNavigator = activeNavigator();
                        if (!showingNavigator) {
                            navSettingsVP.setVisibility(View.VISIBLE);
                        }
                    } else {
                        Toast.makeText(activity, "Current Location not available, Check your GPS signal!", Toast.LENGTH_SHORT).show();
                    }
                    return true;
            }
            return false;
        }
    });
}
Also used : GeoPoint(org.oscim.core.GeoPoint) ViewGroup(android.view.ViewGroup) MapView(org.oscim.android.MapView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) GeoPoint(org.oscim.core.GeoPoint) MotionEvent(android.view.MotionEvent)

Example 17 with GeoPoint

use of org.oscim.core.GeoPoint in project PocketMaps by junjunguo.

the class MapActions method activeNavigator.

/**
 * drawer polyline on map , active navigator instructions(directions) if on
 * @return True when pathfinder-routes will be shown.
 */
private boolean activeNavigator() {
    GeoPoint startPoint = Destination.getDestination().getStartPoint();
    GeoPoint endPoint = Destination.getDestination().getEndPoint();
    if (startPoint != null && endPoint != null) {
        // show path finding process
        navSettingsVP.setVisibility(View.INVISIBLE);
        View pathfinding = activity.findViewById(R.id.map_nav_settings_path_finding);
        pathfinding.setVisibility(View.VISIBLE);
        MapHandler mapHandler = MapHandler.getMapHandler();
        if (Variable.getVariable().isDirectionsON()) {
            mapHandler.setNeedPathCal(true);
        // rest running at
        }
        return true;
    }
    return false;
}
Also used : GeoPoint(org.oscim.core.GeoPoint) MapHandler(com.junjunguo.pocketmaps.map.MapHandler) MapView(org.oscim.android.MapView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView)

Example 18 with GeoPoint

use of org.oscim.core.GeoPoint in project PocketMaps by junjunguo.

the class MapActivity method updateCurrentLocation.

/**
 * Updates the users location based on the location
 *
 * @param location Location
 */
private void updateCurrentLocation(Location location) {
    if (location != null) {
        mCurrentLocation = location;
    } else if (mLastLocation != null && mCurrentLocation == null) {
        mCurrentLocation = mLastLocation;
    }
    if (mCurrentLocation != null) {
        GeoPoint mcLatLong = new GeoPoint(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude());
        if (Tracking.getTracking().isTracking()) {
            MapHandler.getMapHandler().addTrackPoint(mcLatLong);
            Tracking.getTracking().addPoint(mCurrentLocation, mapActions.getAppSettings());
        }
        if (NaviEngine.getNaviEngine().isNavigating()) {
            NaviEngine.getNaviEngine().updatePosition(this, mCurrentLocation);
        }
        MapHandler.getMapHandler().setCustomPoint(mcLatLong);
        mapActions.showPositionBtn.setImageResource(R.drawable.ic_my_location_white_24dp);
    } else {
        mapActions.showPositionBtn.setImageResource(R.drawable.ic_location_searching_white_24dp);
    }
}
Also used : GeoPoint(org.oscim.core.GeoPoint)

Example 19 with GeoPoint

use of org.oscim.core.GeoPoint in project PocketMaps by junjunguo.

the class GeocoderLocal method findCity.

private ArrayList<AddressLoc> findCity(String searchS, int maxCount) throws IOException {
    ArrayList<AddressLoc> result = new ArrayList<AddressLoc>();
    CityMatcher cityMatcher = new CityMatcher(searchS);
    String mapsPath = Variable.getVariable().getMapsFolder().getAbsolutePath();
    mapsPath = new File(mapsPath, Variable.getVariable().getCountry() + "-gh").getPath();
    mapsPath = new File(mapsPath, "cityNodes.txt").getPath();
    AddressLoc curAddress = new AddressLoc();
    try (FileReader r = new FileReader(mapsPath);
        BufferedReader br = new BufferedReader(r)) {
        String line;
        while ((line = br.readLine()) != null) {
            if (GeocoderGlobal.isStopRunningActions()) {
                return null;
            }
            if (result.size() >= maxCount) {
                break;
            }
            if (line.startsWith("<node ")) {
                curAddress = curAddress.ensureCopy();
                double lat = findDouble("lat", line);
                double lon = findDouble("lon", line);
                curAddress.location = new GeoPoint(lat, lon);
            } else if (line.startsWith("<tag ")) {
                String key = findString("k", line);
                if (key == null) {
                    continue;
                }
                if (key.equals("name")) {
                    String val = findString("v", line);
                    curAddress.city = val;
                    if (!curAddress.isAdded) {
                        boolean isMatching = cityMatcher.isMatching(val, false);
                        if (isMatching) {
                            result.add(curAddress);
                            curAddress.isAdded = true;
                        }
                    }
                }
                if (key.contains("postal_code")) {
                    String val = findString("v", line);
                    curAddress.postalCode = val;
                    if (!curAddress.isAdded) {
                        boolean isMatching = cityMatcher.isMatching(val, true);
                        if (isMatching) {
                            result.add(curAddress);
                            curAddress.isAdded = true;
                        }
                    }
                }
            }
        }
    } catch (IOException e) {
        throw e;
    }
    return result;
}
Also used : GeoPoint(org.oscim.core.GeoPoint) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File)

Example 20 with GeoPoint

use of org.oscim.core.GeoPoint in project PocketMaps by junjunguo.

the class MapHandler method setCustomPointIcon.

public void setCustomPointIcon(int customIcon) {
    this.customIcon = customIcon;
    if (customLayer.getItemList().size() > 0) {
        // RefreshIcon
        MarkerItem curSymbol = customLayer.getItemList().get(0);
        MarkerSymbol marker = createMarkerItem(new GeoPoint(0, 0), customIcon, 0.5f, 0.5f).getMarker();
        curSymbol.setMarker(marker);
    }
}
Also used : GeoPoint(org.oscim.core.GeoPoint) MarkerSymbol(org.oscim.layers.marker.MarkerSymbol) MarkerItem(org.oscim.layers.marker.MarkerItem)

Aggregations

GeoPoint (org.oscim.core.GeoPoint)25 File (java.io.File)5 RecyclerView (android.support.v7.widget.RecyclerView)4 View (android.view.View)4 AdapterView (android.widget.AdapterView)4 Location (android.location.Location)3 ViewGroup (android.view.ViewGroup)3 TextView (android.widget.TextView)3 Instruction (com.graphhopper.util.Instruction)3 ArrayList (java.util.ArrayList)3 MapView (org.oscim.android.MapView)3 MarkerSymbol (org.oscim.layers.marker.MarkerSymbol)3 Address (android.location.Address)2 MotionEvent (android.view.MotionEvent)2 IOException (java.io.IOException)2 BuildingLayer (org.oscim.layers.tile.buildings.BuildingLayer)2 VectorTileLayer (org.oscim.layers.tile.vector.VectorTileLayer)2 LabelLayer (org.oscim.layers.tile.vector.labeling.LabelLayer)2 MapFileTileSource (org.oscim.tiling.source.mapfile.MapFileTileSource)2 Intent (android.content.Intent)1