How to get location from the ploy line in android studio - android

I am creating an android app which is notify location to get off from the bus. It shows bus route by using poly lines and when user enter the destination, it also shows the path from current location. My question is how can I get the location of intercept point. I have attached a screen shot here.enter image description here

This question is a bit ambiguous, I recommend you first search and show your effort (or code) or whatever you did to solve your problem and give more context,for instance, ¿are the routes are in lat,lng format? etc.
Regarding this, there is a lot of algorithms to acomplish what you are looking, like:
How to find if an intersection occurs between two line segments represented by a Latitude and Longitude
Efficient list intersection algorithm
or a mathematic aproach in case you want to programme it by youself:
http://www.wikihow.com/Algebraically-Find-the-Intersection-of-Two-Lines
IMHO I would pre-calculate the intersections points before, store it and then compare it with the realtime position (lat,lng) of the users. If the user is near one of the intersections (with algorithms like: How to calculate the bounding box for a given lat/lng location?), show it.
Hope it helps.

Related

Best technique for storing custom map polygons in Android and ray casting

I'm fairly new to Android and trying to develop an app that identifies if a user's location is inside or outside of a given region within a state. My approach is to take the user's latlng and use ray casting to identify which region they are inside (they must be inside 1). My regions are best equated to state park lines, but Google does not have these in Google Maps (and they're too irregular for geofencing). As such, I created customer polygons. I'm not struggling with the code, but struggling with the best way to handle data.
How should I store and access the polygon data for ray casting? I was taking the approach of storing the polygons in an XML file but I'm worried about the time and processing power it may take to parse the XML and run a ray casting across up to 30 polygons in a given state. My polygons are complex enough that the XML file for one state is upwards of 4MB. My polygons only need to be read, not written, as they'll come with the app.
I think that your best option is to store your polygons is a geographic database. The best solution I've found so far to do so is SpatiaLite which is build over SQLite and works really well on Android.
Using this approach you will store you polygons in the database and query what polygons intersect with a given LatLng (Point). The query will look like this (not tested):
select * from polygons_table where st_intersects(Geometry, MakePoint(longitude, latitude, 4326));
Note that I use 4326 as the SRID because I assume that you will store your polygons in WGS84.
Here you can find the SpatiaLite 3.0.0-BETA SQL functions reference list.

How to display a route given some points in a database?

I have an application that needs to display the path taken.
The coordinates are stored in a database. In a similar question,
it was suggested to use drawTrackElement. That requires the data to come from a file. Is there a way to build the list of points in memory or use the database directly?
Try a polyline: http://developer.skobbler.com/getting-started/android#sec009 and see if the result is acceptable to you (if you have enough points in the polyline then the result should be quite smooth).

Tracking GPS points and finding their nearest neighbours?

I have a list of 1 million (slowly) moving points on the globe (stored as latitude and longitude). Every now and then, each point requests a list of the 100 nearest other points (with a configurable max range, if that helps).
Unfortunately, SELECT * SORT BY compute_geodetic_distance() LIMIT 100 is too slow to be done by each point over and over again. So my question: how should I handle this efficiently? Are there better algorithms/datastructures/... known for this? Or is this the only way and should I look into distributing server load?
(Note: this is for an Android app and the points are users, so in case I'm missing an android-specific solution, feel free to say so!)
For your task geo spatial databases have been invented.
There is Oracle Spatial (expensive) and PostGres (free).
These databases store your millions points in a geographical index, a quad tree (Oracle).
Such a query needs nearly no time.
Some people, like me prefer to leave the database away and build up the quadtree themselfs.
The operations search and insert are easy to implement. Update/delete can be more complex.(Cheapest related to implementation effort, is to build up a new quadtree evry minute)
Using a quadtree you can perform hundreds or thousansds of such nearest 100 points within a second.
Architecturally I would arrange for each "point" to phone home to a server with their location when it changes more than a certain amount. On the server you can do the heavy lifting of calculating the distance between the point that moved and each of the other points, and for each of the other points updating their list of the 100 closest points if required. You can then push changes to a point's closest 100 list as they happen (trivial if you are using App Engine, Android push is supported).
This reduces the amount of work involved to an absolute minimum:
Only report a location change when a point moves far enough
Only recalculate distances when a report is received
Don't rebuild the closest 100 list for a point every time, build the list once, then work out if a point that has moved is going to be added or removed from every other point's list.
Only notify a point of changes to its top 100 list to preserve bandwidth.
There are algorithms that you can use to make this super-efficient, and the problem has a fork/join feel to it as well, allowing you to throw horsepower at the problem.
You have to divide the earth into zones and then use an interior point algorithm to figure out what zones the phone is in. Each possible subset of zones will uniquely determine the 100 closest nodes to a fair approximation. You can get an exact set of 100 nodes by checking distance one by one against the candidate nodes, which (once again) are determined by the subset of zones.
Instead of r-tree or a quadtree, I.e spatial index you can also use a quadkey and a monster curve. This curve reduce the dimension and completetly fills the space. You can download my php class hilbert curve from phpclasses.org. You can use a simple varchar column for the quadkey and search the levels from left to right. A good explanation is from Microsoft Bing maps quadkey website.

Image OCR Android

I am working on an android application in which I have to perform OCR from an Image. For example if I have drawing of building, user clicks on a particular area on the image (like Kitchen or Parking lot), after that click I want the location name/number where the user have clicked. This number will be present in that location.
in the given image if i click on Lecture Room part then the application must detect the area where I have clicked and give me the name (i.e. Lecture Room) for further queries..
Please help me out. I have tested many applications but most of them detects words not the drawing images.
Edit
It is just like HTML Image Maping
Interesting project, I've been developing an Android app with OCR and I included useful information and a code example in the next post, have a look at it and if you have any question, just ping me:
https://solidgeargroup.com/ocr-on-android
I'd say that you need to work on how you have abstracted your problem, if the goal of the application is to read any image file and extract all the text from it in order to make it searchable, you've got quite a project ahead of you.
However, if your goal is to make a finite number of maps clickable, I'd say that you should create a table of all the known locations in each image and then save the coordinate where the user clicked. That way you can look up that coordinate in your table of known locations and present the corresponding room to the user. A room could for instance be defined by the coordinates of its northwest corner and its southeast corner. Determining whether or not a coordinate is within those boundaries is trivial.
If your application really requires OCR you are in a world of trouble I'm afraid.
Edit: minor mistakes edited out.

How to store lots of longitudes/latitudes on an Android device

I am looking into writing an Android app that has a database of approximately 2000 longitudes and latitudes which are effectively hard coded.
I assume that once my app is installed, I can put this information into the SQLite database, but how should I distribute this information when the app is downloaded?
One option I thought of was some kind of Patricia Trie to minimise the size of the data (the points will be in a number of clusters, rather than evenly distributed), but I'm not sure whether such a collection would work when there are two associated numbers to store, along with perhaps some other information such as place name.
Does anyone have any thoughts, input or suggestions?
Rich
2000 ints is not many.
In fact I recently tried to load up my web app that has similar numbers for lat lon. I realized i need to optimize a bit, but its load time wasn't completely terrible.
You may want to just request the data you need at any given moment. There must be some other data associated with the lat lons that can help you with that... or maybe you should only display pins within some boundary of lat lon, like +1,-1 in every direction of the center of your map or something.

Categories

Resources