We are developing a travel app project to facilitate customized travel experience. Where traveller can plan its trip by selecting various facilities like ATM, Restaurants, attraction points while traveling from an origin to destination. Facilities coordinates across India has been stored in our database as prerequisite.

I am looking for a logic, that will help me choosing all facilities that are 5 KM radius from the driving route. Also the distance and travel time should be shown while planning the trip.

The existing logic that we have used is,

  1. Pick all Google waypoint using Google API for a particular motorized route i.e. origin to destination.
  2. Using haversine formula to find other waypoint in 5KM radius for that route.
  3. Using vlookup shortlist all facilities that are falling in 5KM radius waypoints.
  4. For accuracy, fetch motorized distance and travel time from Google distance matrix API.

The above logic is working but is not optimized for number of Google API calls. It is generating huge number of Google API calls while planning a trip.

Is there any better logic that can be used with minimum number of Google API? Can ML help me in optimize the logic, if yes which algorithm/logic will help me optimising this logic.

Recommended Answers

All 3 Replies

Frankly this may be a case of accuracy versus costs. Item 4 for example may be low value. Why do any of this for targets the user has little interest in? That and the time to travel 5 KM versus 5.1 KM has little need to be accurate. You could after some runs loosen up on accuracy and lump everything into loose categories of time like "under 5 minutes away" to other groups. Being accurate will be costly.

Is there any logic behind needing an API key for rendering Google maps or is it Google just waving a big stick and saying do as we tell you to do?

Google MUST have changed something in the last 3-4 weeks. You now require an API code it seems if you are using a php file.

Insert the code into a php file and it won't work - the error apppears - no map

Insert that code into a html file and it will work - the map appears

Why and how is it detecting if the page is a php page or an html page?

So to sum this up it appears no API code is required if the file extension is .html BUT an API key is required if the file is a .php extension - it just doesnt make much sense.

Regard
Daniel

To the best of my knowledge, the API key has always been required, but that's beside the point.

The reason it doesn't work in PHP pages is because there is no such thing as a 'PHP page'. There are PHP scripts, but the pages themselves aren't PHP, they are script-generated HTML (and maybe script-generated CSS and/or JavaScript along with it).

PHP runs entirely server-side, and its primary output is an HTML page that gets sent to the browser. Once it is at the browser, there is nothing to show that wasn't a static HTML page all along, save for file extension in the URL - an extension that is there solely to tell the server that it has to pass the file to the PHP interpreter and then serve the output of the script instead of the file itself.

There may also be client-side scripting, using JavaScript (or some other web-scripting language which the browser might recognize, though JavaScript is the closest to being universal), but that's a separate topic. None of the PHP code goes to the browser, so anything that needs to run client-side has to be something else - even if that client-side script was itself generated by the PHP script.

So why doesn't the API key work in a PHP script? Because by the time the key is used, the PHP script has already run its course. You can't use an API key in a script that is no longer running, and when the script was running, it didn't have the user input that the key is applied to yet.

To get the PHP script to use the API key, you would need to get the user input (either with the native HTML forms tools, or some kind of client-side script), then request the PHP scripted page with the user data sent to it as a GET or PUT, and then the script can generate an HTML page that uses the API key.

It requires you to go back and forth to the server every time you get new data from the user, which is why most things like this are done using client-side scripts instead - especially since the API key requires JavaScript anyway AFAIK.

A PHP script generating vanilla HTML does has the advantage that you can, with some finesse (and a willingness to take the performance hit of repeated server requests) avoid any client-side scripting that might get disabled by a script blocker. However, even if the Google Maps API didn't require it to begin with, that probably wouldn't be feasible for this particular sort of application, or anything else where fine user input is paramount.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.