Find cities within given mile radius from address - javascript

I'm using CakePHP/mysql to build my app and I'm trying to get a list of cities within a given mile radius around an address both supplied by the user. So far I have a list of all US cities in a database with the long/lat. I also am using a CakePHP plugin to get the long/lat of all addresses inserted into the database.
Now how do I do the last part? I'm new to the google maps api but it looks like there is a limit on how many queries I make a day. The only way I can think to do it is to check the distance from the address and compare it to every city in the database and if it is within the given radius then they are selected. It seems like this would be way too database intensive and I would pass my query quotas in one go.
Any ideas?

It sounds like you're trying to determine if a given point (city) is within a circle centered on a specific lat/lon. Here's a similar question.
Run a loop over each city and see if it satisfies the following condition:
if ( (x-center_x)2 + (y-center_y)2 <= radius2 )
If this is too slow, you could turn it into a lookup based on rounding the lat/lon. The more values you precompute, the closer to exact you can get.

Related

Find frequently visited area from given set of GPS points

I am having a data set of say 10000 GPS points. I need to find GPS points depending on how frequently the area is visited by using the GPS data set I have. I am looking for a solution either by using google maps or by using mongoDB, but unable to find any clue how should I achieve this. Can anyone help me regarding this?
sample data = [{18.5204303,73.8567437},{18.520457, 73.856697},{18.520400, 73.856800},{18.520156, 73.857092},{18.519879, 73.857561}]
Out of the given data set first three point are near to each other.
So, whenever I will ask for frequently visited area from the given data set I should get result as [{18.5204303,73.8567437},{18.520457, 73.856697},{18.520400, 73.856800},{18.520156, 73.857092}]
I got the solution using google heatmap. I just passed array of gps points to heatmap and the heatmap displayed it in proportion of frequent access to the locations. That is what I was trying to achieve

Calculating likely journey matches based upon their physical locations

I need your help. I have a database table called 'journeys' which contains (fromlat, fromlng, tolat, tolng) and I also have another table called 'cityPostcodes' which contains (postcode, lat, lng).
Users can search journeys by just entering 'from postcode' and 'to postcode'. After mapping these postcodes to their actual physical locations, I want to calculate likely journey matches based upon these postcodes.
What I am struggling is, how to check if two journeys are heading to the same direction? for example, the journey searched by the user and those in the 'journeys' table.
You could use something like the geospatial extension for PHP to calculate the cardinal direction of the from/to lat/long coordinates to see if they head in the same cardinal direction.
You would need an origin latitude/longitude set of coordinates and a destination lat/long for each journey. You can then using something like the Haversine formula or Vincenty's formulae to calculate distince and derive the cardinal North/South/East/West direction of the line segments along the ellipsoid.

How to get cities near my

I want to get all cities close to my actual geolocalisation (by GPS) in a X radius. A good example is the app Tinder. The user select the value of radius in KM and the app gets all the cities close to his geolocalisation inside the selected radius.
I want to calculate the radius and get all cities within by javascript or PHP.
An illustration:
You can download a database of all US cities, with their states and latitude/longitude, then query the database based on current GPS info. Just google search for a DB, they are about 30 meg, so make sure your queries are optimized.
Here is a db that should work...
https://www.maxmind.com/en/free-world-cities-database
If you can find a geospacial database it would perform better (not sure if linked one is or not). I have used a non geospacial one and it was fine though.

How to do customer Lat-Long place search in radius using google map api?

I have set of previously obtained latitude & longitude using GIS application for various places.
What i have to do is... I want to show these obtained lat-long on map as marker from my current location to certain radius.
Say if my current location is -33.8665433, 151.1956316 and radius 1000 then I want to show all obtained lat-long as marker falling in this range.
This : https://google-developers.appspot.com/maps/documentation/javascript/examples/place-search helps for specific defined place type. I don't have predefined type.
How to solve this?
Thanks in Advance.
The problem with geo-queries on AppEngine is that datastore limits inequality queries to at most one property. I.e. you can not perform an inequality query on both lat and lon , which basically limits the geo-proximity queries.
The solution is to geo-hash your data: break the map into discrete grid and give each quadrant an ID. Then also mark all places with the appropriate quadrant ID.
An example of geo-hash on AppEngine. There is also a java library that performs geo-hashing on AppEngine: https://code.google.com/p/javageomodel/

Google Directions on mobile applications, walking distance between two points - minimize response

I'm working on a mobile app and I would like to calculate the distance between two points using the Google Directions API (http://code.google.com/apis/maps/documentation/javascript/services.html#Directions).
I have a list of places and I would like to show this list ordered by distance (from the user position). This can be done performing a request using Google API, look at the following post, there is a working example:
Android: how to get the walking distance between two geo coordinats?).
My questions:
1) Is it possible to calculate the distance from one origin (my current position) to several points (places) using just one request?
2) Is it possible to reduce the size of the response (in order to reduce network traffic)? I just need distance + required time. I would like tho show the map only when the user click the item in the list.
Many thanks in advance for your help.
Mauro
You should look at google.maps.DirectionsLeg and this example.

Categories

Resources