Get items between latitude and longitude - google-maps

I stored the latitude and longitude from a lot of gasstations in a database. I also made a Google Maps. Now, I want to select the gasstations from my database where latitude and longitude are between the North East Latitude / Longitude and South West Latitude / Longitude from my Google Maps.
How can i calculate which gasstations I have to select?

Simply modify your database query in the backend to only return locations between your points. Something like the first answer here.
Obviously the syntax will depend on the database that you are using.
Actually I would suggest using:
SELECT * FROM tilistings WHERE lat BETWEEN a AND c AND lng between b AND d
Where a and b are you top left coordinates and c and d are your bottom right. I think BETWEEN is more performant.

Related

Comparing different decimal places

I'm trying to match latitude DECIMAL (10,8) and longitude DECIMAL (11,8) in my database by latitude and longitude that only have 4 decimal places. I'm trying to compare addresses but since addresses are all in different formats, I figured latitude and longitude is the next best thing.
So right now I have to do this:
select *
from locations
where (latitude BETWEEN 33.29940 AND 33.29949) AND
(longitude BETWEEN -111.89889 AND -111.89880)
Where I search between 0 and 9 of each number. But it's pretty clunky. I'd rather be able to do something like LIKE %33.2994% instead.
So what's the best way (performance-wise and easy to read) to search these latitude and longitude fields?

What is maximum points limit for Google's heatmap feature?

Hello there's I am use google's Heatmap feature in my project. I do not know whats the maximum points (latitude ,longitude )limit for google's heatmap to visualization.
There is no limit to the number of points added to the heatmap, but there are practical constraints (the memory of the device displaying them, the time to load them, etc.)
Longitude is in the range -180 and +180 specifying coordinates west and east of the Prime Meridian, respectively. For reference, the Equator has a latitude of 0°, the North pole has a latitude of 90° north (written 90° N or +90°), and the South pole has a latitude of -90°.
The limit is for longitude and latitude not for google heatmap feature for using latitude or longitude. If your latitude/longitude is in valid range , it will work.

Correctly draw on Google Maps a point which exceeds 90 degrees of latitude

I'm working on a simulator that plots the flight path of an aircraft on Google Maps.
The simulator is not aware that the latitude is only defined between -90 and +90 degrees and the longitude between -180 and +180 deg. As a result of this, the flight path may include points beyond the map boundaries. Exceeding in longitude is not an issue as it still plots correctly (a point at longitude x and x+360 is the same), but the latitude is a problem.
Is there any way of telling Google Maps to keep the points between the correct boundaries and plot them correctly?
Otherwise, do you have any ideas of where to find functions that do so?
Longitude, latitude and elevation are a bad coordinate system for a flight simulator, because the mapping presents singularities i.e. there are points infinitely close on the earth that have very different coordinates. For example where you're close to one of the poles longitude variation speed can become arbitrarily big compared to airplane speed. When standing exactly on the pole the longitude doesn't even make sense.
A better solution is to use an XYZ coordinate system for the simulator and only convert to longitude/latitude and elevation for plotting. If you can approximate the earth to a sphere for your use case the computation of this transformation is trivial... otherwise things can get much more complex depending on how accurate you want it to be.
That said it's still possible to give "a" meaning to a point with latitude slightly outside the range -90...90 by extending it over the pole...
if latitude < -90:
latitude = -180 - latitude
longitude = longitude + 180
if latitude > 90:
latitude = 180 - latitude
longitude = longitude + 180
but using this coordinate system for navigating is a very bad idea (the same point in space can have multiple triplets of coordinates).
If your simulator doesn't know that the maximum value for latitude is 90 degrees it is broken and needs to be fixed. Google Maps works correctly for valid/possible values of latitude and longitude.

Eeek! - Calculate Radius having only latitudes and longitudes

I have a MySQL database that looks as such:
Postcode int(4),
City varchar,
State varchar,
Latitude decimal(7,4),
Longitude decimal(7,4)
I want the user to enter their post code (1660 for example) and a radius of x (lets say 10) miles or kilometers. When they hit search, I want to return a list of all the cities within that radius. I have a database that contains all of the post codes, cities, latitudes, longitudes etc. of all areas within Australia.
If you could sacrifice some precisions (by selecting cities within a rectangle area 10 miles from post code 1660), then the solution can be as simple as:
Find out the latitude and longitude of post code 1660
Calculate the top left and bottom right of the rectangle area (10 miles to the left and top, 10 miles to the bottom and right)
Use the query like: select city from table where latitude between bottom_right_latitude and top_left_latitude and longitude between top_left_longitude and bottom_right_longitude
If it has to be precisely radius 10 miles (which means the area is a circle), then the solution will be very complicated, couldn't do it in a single query I afraid. You need to think about some helper columns and use the distance and bearing calculations formulas to do it.
Reference: Calculate distance, bearing and more between Latitude/Longitude points

to find locations in google map within 5 km radius of a given point

hey i just want to gather the locations in google maps database which are under 5 km radius of the given point.. i will be storing them in database for later processing .....can this be done...thanks...how to get longitude and latitude of points with in the required circle...
You can use PlaceSearches
with the parameter : radius