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;
}
});
}
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;
}
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);
}
}
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;
}
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);
}
}
Aggregations