KortidTol


Source link: https://github.com/fiskurgit/KortidTol

Kortið tól

Map tools for GoogleMaps on Android.

Dependency

Add jitpack.io to your root build.gradle, eg:

allprojects {

  repositories {

jcenter()

maven {
 url "https://jitpack.io" 
}

  
}
 
}

then add the dependency to your project build.gradle:

dependencies {

  compile fileTree(dir: 'libs', include: ['*.jar'])
  compile 'com.github.fiskurgit:KortidTol:1.0.6' 
}

You can find the latest version in the releases tab above: https://github.com/fiskurgit/KortidTol/releases

More options at jitpack.io: https://jitpack.io/#fiskurgit/KortidTol

Licence

Full licence here: https://github.com/fiskurgit/KortidTol/blob/master/LICENSE

In short:

The MIT License is a permissive license that is short and to the point. It lets people do anything they want with your code as long as they provide attribution back to you and don’t hold you liable.

Limit Bounds

** Note - LimitBounds is deprecated, use the native setLatLngBoundsForCameraTarget instead **

Create Bounds

Either provide four outlier coordinates or an array of LatLng pairs and return a bounding box LatLngBounds object:

LatLngBounds threePeaksBounds = MapTools.createBounds(MIN_LAT, MAX_LAT, MIN_LON, MAX_LON);
  //or  LatLng[] multipleCoords = ... LatLngBounds threePeaksBounds = MapTools.createBounds(multipleCoords);

Nearest Index

Find the nearest index in an array of coordinates to a point, for example when a user long-clicks on a map near a route, find the nearest point on the route:

map.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {

@Override public void onMapLongClick(LatLng latLng) {

  int nearestIndex = MapTools.nearestIndex(routeCoords, latLng);

  LatLng nearestRoutePoint = routeCoords.get(nearestIndex);

}
 
}
);

Long Click Helper and Draw Subsection

Manage long-click events with a map to help draw a route subsection.

LongClickHelper longClickHelper = new LongClickHelper();
  ...  map.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {

@Override public void onMapLongClick(LatLng latLng) {

  vibrator.vibrate(175);

  longClickHelper.addPoint(latLng);

  if(longClickHelper.isReady()){

 LatLng startClick = longClickHelper.getStart();

 LatLng endClick = longClickHelper.getEnd();

 MapTools.drawSubsection(map, routeCoords, startClick, endClick, Color.parseColor("#ff00cc"));

  
}

}
 
}
);

Subsection Distance

Calculate the distance of a subsection of a route

float meters = MapTools.subsectionDistance(routeCoords, startCoord, endCoord);

Quick (Convex) Hull

There's a Quick Hull implementation included (adapted from code by Jared Rummler) which can be used for displaying the bounding shape ( Concave Hull) of GeoJson polygons. Rather than expensive rendering of a shape consisting of thousands of points draw the bounding shape instead ( more detail here). The new single-pass method calculates the hull of an array of 580 coordinates in 4ms, versus 66ms for the older method:

New method

List<LatLng> polygonPoints = MapTools.getPoints(jsonString);
 ArrayList<LatLng> hullLatLng = new QuickHullLatLng().quickHull(polygonPoints);
 Polygon hullPolygon = map.addPolygon(new PolygonOptions()
.addAll(hullLatLng)
.strokeColor(Color.parseColor("#22000000"))
.strokeWidth(0)
.fillColor(Color.parseColor("#22000000")));
 
}

Old method (may be deprecated in future)

List<LatLng> polygonPoints = MapTools.getPoints(jsonString);
 QuickHull quickHull = new QuickHull();
 ArrayList<Point> points = quickHull.convertToPoint(polygonPoints, map.getProjection());
 ArrayList<Point> hull = quickHull.quickHull(points);
 ArrayList<LatLng> hullLatLng = quickHull.convertToLatLng(hull, map.getProjection());
 Polygon hullPolygon = map.addPolygon(new PolygonOptions()
.addAll(hullLatLng)
.strokeColor(Color.parseColor("#22000000"))
.strokeWidth(0)
.fillColor(Color.parseColor("#22000000")));
 
}

Concave Hull

There's also a Concave Hull method which uses code by Eric Grosso. This is much more complex than the Quick Hull implementation, a native 'single-pass' conversion is beyond my capabilities (or at least available time). The method converts the LatLng array to points and back again so it will be much slower than the new native Quick Hull method above. A threshold of 30 reduces a ~5000 point polygon to ~800 points.

List<LatLng> polygonPoints = MapTools.getPoints(jsonString);
 double threshold = 30; List<LatLng> concaveLatLng = new ConcaveHull(polygonPoints, threshold, map.getProjection()).getHull();
 Polygon concavePolygon = map.addPolygon(new PolygonOptions()
.addAll(concaveLatLng)
.strokeColor(Color.parseColor("#66000000"))
.strokeWidth(0)
.fillColor(Color.parseColor("#66000000")));

Resources

This plugin provides a task to generate a HTML license report based on the configuration. (eg. licenseDebugReport for all debug dependencies in an Android project).

Applying this to an Android or Java project will generate a the license file (open_source_licenses.html) in the <project>/build/reports/licenses/.

Extended management of fragments for the Android platform.

View and navigational transitions for the Android platform.

Awesome Image Picker library will pick images/gifs with beautiful interface. Supports image or gif, Single and Multiple Image selection.

Cryptographic tools for the Android platform.

Simple universal framework for the Android platform that may be used as base for Activities and Fragments in Android applications.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes