Find POI along a Google Maps route? (Android) - android

doing "points of interest along a route" in google maps
This would fit perfectly to my question...... But its not suitable for an android activity :/
So I start copiing the question now... just wait :D... aargh! Done!
I need to allow travelers to use google maps to plot a route, and then
query my database of points of interest (let's say, McDonald's
locations) and then show all of these locations that are within a mile
or two of the route they will be taking. The question is, how do I
efficiently take the "driving directions" information that comes back
from google (essentially an array of lat/long pairs), and turn that
into an sql query to get locations that fall within a certain distance
from the route?
...and then put the whole thing into my android app?
I dont get it :(

First things first:
1) do you have latlng (geolocations) variable type in your database?
If answer(1) == yes:
Calculate and query your database: D²=(Xb-Xa)²+(Yb-Ya)² along each of your Xa,Ya route points to discover the POIs (Ya,Yb) within Distance = D.

Related

How can I use Graph data structure to generate route with exact distance using Google API in Android?

I need help with my final CS Project. Basically, I have to write an Android app that the user can specify a starting location and distance desired. It is going to generate a route that is exactly the distance of the input that the user can walk/ run and brings the user back to the starting location, using the Graph data structure and Google API.
I have my Google map and Android app but I’m not sure where to start with storing data using Graph ( I'm not sure if I should even use this data structure) and how to calculate the distance input. Any bits of advice/ help will be appreciated!
Okay your question is very tricky but still let me answer from what I got.
Use google map api, google places api, place picker or id and google maps json api for routes and distance.
let's take an example like you want walk or run 4kms from your places and comeback.
Case 1: if you want to opt for the same route from which you went to come back.
like you went from a-b then again you are coming bak from b-a.
for this case you can use Google maps geofencing and get the place inside a minimum raidus and make an algo to get the distance from your places.
if teh distance is half of the distance from your places then pick the most approximate place.
Use google maps json to get the places distance and google place picker for the location of nearby location object.
Case2: If you donot want to come from the same route through which you went
by, then select the nearest location object and get the longest route and follow
the same algo and procedure to get the distance.

Get total "Areas/Zones" in which I am currently in, based on Current Location

Let us suppose we have three hotels:
Hotel A (popular in 1 km radius), Hotel B (popular in 2 km radius) and Hotel C (popular in 4 km radius). A car enters and is at some position. These Hotels (or any other place) is added by us and is custom.
Problem is I want to find the hotels which have popularity/influence at my current location.
And I want it to do totally with the help of Google Maps. Is it feasible ? on Android (optional)? Please ELI5.
Google Maps API has a function called computeDistanceBetween. It "returns the distance, in meters, between two latitude/longitude coordinates". Circle has the Center and Radius properties. So you need to calculate the distance between the center of a circle and you current location. If it's less than the radius of the circle, than it means your current location is within the circle.
Simplifying is key
Although I understand your objective (get a list of all hotels near you) I believe your explanation threw many people off guard. You don't need to triangulate positions and calculate radius of circles - not with Google Maps APIs and Services.
All you need to know is if you want a solution for front-end, back-end, or mobile
Google Maps Places API Web Service (back-end)
The Places API has a very useful feature called "Places Nearby". To quote the documentation of this feature:
A Nearby Search lets you search for places within a specified area.
You can refine your search request by supplying keywords or specifying
the type of place you are searching for.
Which looks exactly like what you need, right ?
To make a request from a server to the Places API Web Service looking for nearby places, you can do the following:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&type=restaurant&name=cruise&key=YOUR_API_KEY
Do remember to change the key=YOUR_API_KEY to a valid key field. The example showed will look for restaurants in a radius of 500 meters around the location of -33.8670522,151.1957362.
There are a lot of parameters to this and you can read more about this in the following documentation
https://developers.google.com/places/web-service/search
Google Maps JavaScript API with Places Library (front-end)
If you however don't have a central server or service to make requests for you, making the clients send the requests directly is also an option.
In this case, there is the JavaScript API. The JavaScript API is a client-side friendly API that re-uses some of the Web Service's features.
In this case, you can use the JavaScript API in conjunction with the Places Library for it. According to the documentation, this API allows you to do "Nearby Search Requests":
A Nearby Search lets you search for places within a specified area by
keyword or type
An example of such a request can be seen in a live example in the following link https://developers.google.com/maps/documentation/javascript/examples/place-search
You can read more about the parameters and usage of this API and this library in the following documentation https://developers.google.com/maps/documentation/javascript/places#place_search_requests
Google Maps Android API (mobile)
From the picture you added, I assume your app will be to "use on the go" (perhaps a mobile app), or something similar.
In this scenario, using a web-server or a website could be cumbersome, as by the time you have a response from it, the car is already in another position !
To aid you in this, there is also the Android API. To use it you need to:
Download and Install Android Studio
Add Google Play Services Package (contains APIs you will use)
You can read more about this process here https://developers.google.com/maps/documentation/android-api/start
As for code and examples, I strongly suggest you check out this GitHub repository of samples
https://github.com/googlemaps/android-samples
Our Hotels may not show up on Google Maps
Unless your DeLorean takes you back to the latter half of the 19th century, or you are stuck in an island with hundreds of Meerkats, poisonous pools and a tiger wondering if he should eat you or not, Google Maps will pretty much always show you some hotels where you can spend the night.
PS: kudos++ if someone gets my references :P
Adding Hotels and Places to Google Maps APIs and Services
If this is still not enough however, there is still a way you can fix it. You can add Hotels addresses and Places to Google Maps by using one for the two following methods:
Send Feedback
Use Maps Maker
Send Feedback
The "Send Feedback" feature allows you to send feedback to Google's data teams for review. Once approved, the data is added to Google's database and will be available to all Google's customers. You can do this by following the steps described here https://support.google.com/maps/answer/3094045?co=GENIE.Platform%3DDesktop&hl=en
Please do note however that the review process for your feedback will take some time, so don't expect anything instantaneous !
Use Maps Maker
Alternatively, you can use Maps Maker. This tool allows you to do edits and add information to our Services in a more streamlined manner.
At first, your edits and suggestions will still be reviewed, and it will usually take less than two weeks to get something approved.
However, with time, as more and more of you suggestiogns are approved, you gain reputation, and when you have a lot of reputation, your suggestions will be pretty much automatically added.
Before using it however, make sure you have a look at the list of supported countries.
Also, if language is important, you may want to consider it as well, by checking the list of supported languages.
I really don't want to add anything to Google Maps
Sometimes the whole business is data itself, so giving it out freely is not an option.
In these cases, you will have you own database, which your services will have to check.
In cases like this a custom solution for your system is needed, but in order to suggest a few more ideas, more information is needed.
Hope it helps !
Your approach should use fast approximate calculations without relying on apis, and then api usage can be used to enhance user experience.
You know the coordinates of the car.
You know the coordinates of each of the hotels.
Assign a popularity weight to each hotel based on your criteria or data you have. e.g a hotel having more user reviews or transactions or bookings will have higher influence, or if you want to personalize, a hotel which suits the loggedin user's budget preferences ( based on past data or settings ) will have higher influence. Lets call this popularity value p1,p2..p3 etc.
Find all hotels that lie within a threshold range, say 5kms within current position of the car. This can be done using a geospatial query in any major storage database ( for example if your hotel points are stored in MySQL, or mongodb ), or if you are using a hotel data api, get the nearby hotels,or all hotels of that city, and prune them based on distance from car's current location.
For linear distance between the car C, and the hotels H1, H2... use Haversine formula , this will give you distance between the Car and any hotel along the Earths curvature. ( Actual road distance might vary, as roads are directions aren't straight and involve turns etc). But this will give you a fast approximation of distances D1 between C & H1, D2 between C & H2 etc...
Now decay the popularity score P1...PN of each hotel based on distance between the Car C and the hotel H. For example if hotel H1 has popularity score P1= 90, and hotel H2 has popularity score P2=90, but C <---> H1 distance is 10kms, and C<--->H2 distance is 2kms,
then H2 will have more influence on the current location compared to H1.
A simple formula can be LocationInfluence = PopularityScore/ log(Distance), you can optimize this based on your use case.
Now for the most influential hotels H1,H2,H3... use DistanceMatrix api to find actual driving distance, you can also use google maps directions api for Android or Javascript to show driving directions to the user, from location till the hotel.

How to find the distance between two points along a specific route?

I'm developing an android app for my college that helps students track the current location of the college bus and also give them an estimated time when the bus might reach them. As of now I get the current location of the bus(via a device present on the bus) and the location of the student. I'm stuck at the point where I have to find the distance between the two GPS co-ordinates. I have to find the distance between the bus and the student "along a specific route" (i.e the path the bus takes). Using Google Map APIs will not always give the distance along the route I want. How do I find the distance between two points along a specific route?
The Google Maps Android API Utility Library has a range of applications useful for your case, including calculating distance between two points, by using the computeDistanceBetween(LatLng from, LatLng to) method from the SphericalUtil class.
Also check this link.
Google Distance Matrix API provides travel distance and time for a matrix of origins and destinations.
Or you could try Google Directions API.
Also, I believe this guy had the same doubt of yours.
Hope this helps you.
I would it solve this way:
1) The direct line of sight distance betweent two GPS points is simple, simply use Location.distanceBetween() method, you will find hundres of posts here on SO.
2) The length of the route.
This part is more difficult. If you are not happy with the result of google:
Store your bus routes as rough sequence of lat/lon coordinates (a poly line). A point per street corner should be sufficient.
Then find the nearest point on the route, a simple brute force search should be sufficent for your task.
Then simply iterate from found route point till destination point, and sum up using the distanceBetween() method.

Finding nearest Hospital using a stored map

I am trying to develop an android program that finds the location of the nearest hospital WITHOUT using the internet. Instead, I want it to use a stored map on the android device. Is this feasible? If so, Can anyone refer me to the code?
I successfully developed a similar program that uses google API, meaning it will contact the server and use the internet. I reused the source code in this link.
But in some cases, my user might not have an access to the internet and it is urgent to find the nearest hospital. How can I solve this issue?
Another much simpler solution is to store the coordinates of each hospital in a file.
At App start your read the file in.
Possible file format:
Hospital Name, latitude, longitude, Adress Optional
Then simple calculate the line of sight distance to all hospitals using CLLocation distanceTo(). Then sort by distance.
Take the shortest.
Although this is not road distance, it will work as long as there is no river or rail road inbetween
It's definitely possible.
You'll need to use offline map data - you can get map data from the OpenStreetMap project. I'd recommend letting the user choose which areas to download after initial app installation, and then the data will always be available.
Later on, usage of the location API does not require internet connection. You'll get co-ordinates, with which you can calculate the distance to other co-ordinates (of hospitals..).
Obviously, your challenge will be to create a hard-coded list of hospital locations (albeit update-able, make sure the app can download a new list when internet is present, for example download a XML file).

Marking places in android app not on the 'Google Places' database

I want to add markers on map for my android app. I do know how to do it (overlay items). My question is: Since I am manually putting markers on points(on the map) whose lat/long's I already know, I want to know if there is any way to get the exact latitude and longitude of a place on google map? Right now I am asking my people to go to the particular places and use this ( http://bit.ly/K4fOcy ) app to determine the lat/long of that place and send it to me via e-mail. I use these lat/long values to put markers on my map in the app. But the latitudes and longitudes i get are not accurate. they have around 300-2500m error (on real scale).
Or shall I use the Google Places API? How does it work? What about the places which are not in the Google Places database? How do I exactly mark them on the map? I would be very grateful if someone points me in the right direction.
Thanks
If you are working with establishments that aren't represented in the Google Places API and want to be able to pull coordinates directly from http://maps.google.com/, you simply:
Find the location of interest on the map, using an address or just knowledge of the area
Right-click on the map and select What's here? from the context pop-up menu
The Lat-Lng coordinates will be automatically populated in the search input box and usually, the address will also be displayed in the dynamic side-panel (and very often a Street-View photo).
If you are looking for a way to query for the coordinates, you can use the Geocoderdev-guide service to turn addresses into coordinates.
Have you looked at the geocoding API for google maps? It allows you to pass in an address, and returns a Latitude/Longitude pair in response, there is an accuracy value returned with each response to let you know how close the geocoder was able to resolve the location. https://developers.google.com/maps/documentation/geocoding/

Categories

Resources