Finding nearest locations using Google Maps API -


hi i'm writing app shows bike stations near address. have list of latitude , longitude locations of each bike station service.

i can mark current location, or address far. how show bike stations near location on map. first nearest google places current location , access database bike location , make markers on map? best approach?

if have coordinates of bike stations , if trust data, use draw markers. have define "near" means.

you have different solutions this. either choose draw markers bike stations within map bounds (but many markers draw depending on zoom level, or have prevent script drawing markers before zoom level reached) or can draw markers within n kilometers around location (can user location, map center coordinates, etc.).

for second solution, , if storing bike stations in mysql database, query that:

$sql = "select *, ( 6371 * acos( cos( radians(" . $db->real_escape_string($lat) . ") ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(" . $db->real_escape_string($lng) . ") ) + sin( radians(" . $db->real_escape_string($lat) . ") ) * sin( radians( lat ) ) ) ) distance your_table_name having distance < 15"; 

$lat , $lng being center coordinates

lat , lng being mysql column names

15 being radius (in km) around coordinates

this uses haversine formula. information can found here.

hope helps, don't know how organized data in app. give more info if need more on this!


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -