i am developing an app in android that must recieve the distance between two points from the user after traveling between them, and that input must be validated, for that i'm thinking of using an API to get the information and make the validations later. I know that it's not the op to ask the user to enter that kind of input, but that's not on me.
For example, if the distance between point A and point B is 13 km according Google Maps Distance Matrix API, i got from the waze api like 18 km. The approach of the app is one about transport so i would prefer to use waze information because it's more accuarate in terms of road traffic.
So, there's any way to take the distance between two points from waze?
more exactly, this one:
Any help would be appreciated
PD: sorry for bad english
I'm not certain whether you're still looking for an answer, but in theory you could call the Waze routing server in the same way as the Waze Live Map calls it.
The following URL is the request sent to the Waze routing server when I calculate the route between Antwerp and Brussels in Belgium.
https://www.waze.com/row-RoutingManager/routingRequest?from=x:4.4024643+y:51.2194475&to=x:4.3517103+y:50.8503396&at=0&returnJSON=true&returnGeometries=false&returnInstructions=false&timeout=60000&nPaths=1&clientVersion=4.0.0&options=AVOID_TRAILS:t,ALLOW_UTURNS:t
Note: make sure to properly encode this URL when using a script. Those colons and commas might cause issues otherwise.
To calculate the length of a route, you'll need to go through all the traversed road segments and make a sum of the length fields (expressed in metres, if I'm not mistaken).
Do note that the results will differ from time to time as Waze includes historical traffic data in its results and will decide to make detours, which may not be wanted for your use case.
I would also strongly suggest to look into the legal status of doing this, though I suspect it won't be a big issue if you're not using this data to make a competing service or 'forget' to mention you're using Waze data to calculate things.
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.
is using the URLs such as this http://maps.googleapis.com/maps/api/geocode/json?latlng=44.4647452,7.3553838&sensor=true limited by number of queries?
I am asking because I know that GOOGLEs api for location has limited queries.
So, if I know the longitude and latitude, am-I allowed to convert it to a street address as many times as I wish using this URL?
Thanks in advance for response :)
Every request to http://maps.googleapis.com/maps/api/geocode/* is subject to Google Maps Geocode API limits: https://developers.google.com/maps/documentation/geocoding/usage-limits. Consider caching your results, if you expect geocoding the same locations. Before doing that though, read up on Geocoding Strategies (section Caching Considerations) to make sure you don't violate the API's terms of service.
What you're doing is known as "Reverse geocoding", there is quota management on it.
Users of the standard API:
2,500 free requests per day
10 requests per second
$0.50 USD / 1000 additional requests, up to 100,000 daily.
You should (must) also include your API key in the request.
References:
https://developers.google.com/maps/documentation/geocoding/intro#ReverseGeocoding
https://developers.google.com/maps/documentation/geocoding/get-api-key
https://developers.google.com/maps/documentation/geocoding/usage-limits
I develop an application and i need to use somehow with google maps.
I tries both:
1.send request to "http://googleapis.com/maps/api........"(with key..).
2.javascript file of googlemaps.
and now I'm stuck with a big question that i cant find any complete answer(from what i understand).
The question:
I need from any user in my application to use the request something like 5-20 times a day(if the user will be very active). I read that there is a limit of 2500 requests a day. This 2500 requests a day is per user?(sound the limit is only for not flooding google..am i right?). if it is 2500 requests for all users so I need much much much more then 2500.
there is a difference for google if I use option 1 or 2?(regular request/javascript file).
Thanks.
If you are talking about a displaying a Google map to a user, then there are no restrictions.
2500 requests/day is the limit for Google Directions API, which is used to create directions that you can get and display for your users (e.g. driving route from point A to point B).
However if the directions you are getting from the Directions API are repeated over and over, you could just save them as an XML file on your server (or the device) and re-use them, that way you can stay inside the 2500 limits.
I have an application that generates some number of tokens around the current location of the user using a certain distance radius. The user will then have to run to some of those locations. The problem is that some tokens can be created in a lake,forest,ocean, or some other physically unreachable location. As a quick fix I just generate extra tokens and increase the proximity distance that determines if a user reached a certain location. I now want to improve this so that each token is located at a reachable location.
The only solution I have been able to come up with is using the Google Directions API to determine a path from the user to the token and use the last coordinate in the polyline as the new reachable location of the token. My problem with this is that I potentially have to post up to 30 requests to the Directions service simultaneously and I am worried that I might hit the query rate limit. I have not found anything definite about query rate limit.
So my question is whether anyone knows of a better solution or can give any input on the Directions query rate limit? Waiting 1 second between each request and forcing the user to wait up to 30 seconds is not a reasonable solution. Thanks.
UPDATE
Using the solution that I described in the question does produces an OVER_QUERY_LIMIT, even if I wait 1 second between each request. Other then that the logic was sound and tokens that got a request thru were appearing in walk reachable locations.
You can calculate the distance between two lat/lon with Location.distanceBetween(). This is a static convenience API call. There's no limit on number of calulations.
Usage limits
Use of the Google Directions API is subject to a query limit of 2,500 directions requests per day. Individual directions requests may contain up to 8 intermediate waypoints in the request.
Google Maps Premier customers may query up to 100,000 directions requests per day, with up to 23 waypoints allowed in each request.
You might want to take a look into the Maps premier customer so you don't hit the limit too fast. If your app becomes popular I bet you can get an higher limit.
One way would be to see if you can see the elevation to see if it's a cliff or not. However just seeing if it's a lake or not seems to be quite hard. Might be some kind of gps lookup service out there except Google Maps.
If you just want to know the distance between locations just use Location.distanceTo() or static distanceBetween()
Getting the info if it's a road or not is another question.
After some 8 hours I finally got something working. So using the fact that each request can have up to 8 waypoints I can technically ask directions to 9 locations in one request. Here's what I am doing now:
Generate 9 random locations at a time. Pass the locations to my DirectionsComputer which returns the polyline path that goes through all 9 coordinates as a list of coordinates. Then I pick 9 location from the path and set them as the locations of my tokens. Now all my tokens are semi-randomly generated, always appear on a road, and I only need to do 4 consecutive requests to generate 36 tokens.
There are some cases where a few tokens are bunched together. For example, the coordinates which are originally located in the ocean get moved to the same beach. But for the most part, all my tests showed the tokens spread apart and I could tweak the rest.