I'm stuck with one scenario,
We have geofence coordinates created by client/user, and also have user's current location. So want to check that, whether user is belong to that geofence area(coordinates) or not?
We need to check it from backend/server side - Java is there.
Below are the GeoFence coordinates that may stored in our DB:
"42.43588461182335, -71.6158054921875",
"42.448988452992175, -71.61402648035278",
"42.44936844757593, -71.5879339510559",
"42.43299861648753, -71.59088339349671"
User's current location/coordinates which will sent by device to the backend:
42.440593799089996,-71.60585993854373
There are APIs available like (google map client for java) but they are related to Android and other mobile platform specific, not purely Java/backend specific. I want to compare these from server end.
So want some clue or any API that could be helpful to achieve the scenario.
any help would be appreciated, Thank you in Advance..! Have a Good Day.!
If the "backend DB" is MySQL, use PolygonFromText('POLYGON((...))') to define the fence if it is a polygon. There are other functions for other shapes.
Then use any of a few functions to see if a POINT is in the "Geometry".
https://dev.mysql.com/doc/refman/5.6/en/spatial-types.html
You will probably need a SPATIAL index to provide performance.
Related
I am developing an app which will give you nearby Mosques within 10 km of your current location. Now that the Places API allows a certain number of queries per day, I have used firebase to store nearby Mosques for a certain location and I first check if the data is in database or not before querying. But this still doesn't solve the problem. e.g. if a user is on the go the whole day then the results must be changing every single minute, according to his/her location. How can I achieve the desirable results?
As mentioned earlier, I am saving nearby locations in a database with their relative location (around which they exist). But this doesn't quite solve the problem.
Any help will be greatly appreciated.
Places API is a commercial offering - you are meant to pay for using it, if you want to make applications around it.
There's a certain small number of calls that you can do for free, but this is only meant as testing grounds or private use. I am no lawyer, but I would guess that circumventing the fee by scraping the map (like setting a bot to go around a country to build a database of points of interests) would be illegal and would probably get you a letter from Google saying you should stop.
Use AutocompleteSessionToken class to generate a token and place it after your key , this token will reduce your usage because you can request the places api multiple times and still it will be considered as a single request. i hope this will help cause i didnt get your question very well. here is sample of the link:
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=1600+Amphitheatre&key=&sessiontoken=1234567890.
For more details.see here
I'm not asking for anyone to build me an app.
I just need some tips on getting started.
So what I wanted to do:
be able to map some routes/directions, similar to what Google Maps already has regarding the local transit in a city.
Why? Because Google's database is a bit outdated, first. Second, because I want to create a local database with the routes and with the stations. Unfortunately, I can't really do that using Google Maps and I think Leaflet could help me with this much better. This would've been a web app, where someone with an account could add/edit/delete the routes.
create an Android app that :
a) sees the routes, allows an user to find the closest path to get from point A to B using only the routes I have in my database, sort by tram/bus etc
b) allows the user to mark a location and say something like "bus no 37 was here at hour:minute:second" - this would appear for anyone else that is using the app, similar to what another app lets you do this for police cars and traffic jams
c) extra: allow users to input some data so that my app could also give predictions; for example, someone inputs it took 10m50s to get from point X to point Y on route Z. That remains in a database and then someone else inputs some data for the same path...i would create some algorithm that could get predictions on where would a bus be now if someone marked it at Station 'bla' 5 minutes ago. I know, I know, this might be pretty hard, and it would be pretty inaccurate, I should consider the time of day, but it would just be something small, as an extra. Also, would be cool if this stuff could be added automatically: like the user sets the route he's on, starts "recording", then stops it when he gets off the vehicle and the time and locations are automatically taken into consideration.
Hope you understand what I have in my mind.
Thing is, what would you recommend?
I know Java, Spring MVC and a bit of Android. JavaScript, HTML and CSS won't be a problem. I need to combine these. If I will use Leaflet, as far as I can find, I won't really be able to use it in an Android APP, I would have to create a web app. At the same time, Google Maps doesn't really let me do what I want for my "personal" database. I can't even create decent custom routes by adding waypoints because parts of the Tramway Line aren't on streets with car access. ALso, would you think this is easier/better to do as an Android app or as a web app? I'm kinda new to Android.
I hope this isn't an unsuitable thing to ask on stackoverflow.
I'm open to any ideas.
allows an user to find the closest path to get from point A to B using only the routes I have in my database, sort by tram/bus etc
Routing is hard. Multi-modal routing (tram+bus+car+walking+cycle) even more so. See pgRouting and Valhalla. If you're going to do anything with public transport, then you'll have to deal with GTFS too.
Research into OpenTripPlanner also, as there are several actors developing some similar platforms.
I hope this isn't an unsuitable thing to ask on stackoverflow.
I'm afraid it kinda is - see https://stackoverflow.com/help/on-topic, point 4.
i want to build a weather app and i have some problems.
my big problems is places names! you know, i want that user find his location with two ways. with GPS and by searching. but my problem is that place names. how can find a database from whole places in the world?!
is it good idea that i store them in a database in my server? or there is some services that provide this functionality? if i have to create my own database how i can create a database like that. is there a database with city names and latitude/ longitude and other information? if a new location created how i can add it to the system? by hand?
the second problem is that after catching the city name how i can find that locations latitude/ longitude? it seems google has a Geocoder service but i don't know how it works. please help me. i just want to select a city name and find related coordinates...
The Google Maps API provides you with Geocoding, which allows you to turn strings like 'Santiago, Chile' or 'New York', into proper latitude/longitude coordinates. So in your code, you should perform an HTTP GET request to a URL like this one:
http://maps.googleapis.com/maps/api/geocode/json?address=Santiago,+Chile&sensor=true
And it returns a JSON object with a properly formatted address along with latitude and longitude information of the place you were looking up.
It's explained very thoroughly in the Google Maps API Geocoder documentation, so you should probably take a look at that. I'm no expert in Android development, but there should be some library that allows you to easily access what the Maps API has to offer in a clean way.
Maps API also provides you with a solution for Place Searching, and even input autocompletion, but all the examples I see are on JavaScript/HTML, so I'm not completely sure if there's an alternative in plain Java/Android to what you're trying to do. Nevertheless, you should take a look at basic place searching and place search autocompletion so you get a general sense of how it works.
There's an entire section in the Google Developers website dedicated to the Maps API on Android, so make sure to take a look at that aswell and you might find more useful information - sadly I have no experience with Android whatsoever so I can't really point you in any direction.
Good luck!
You could use the Google Maps Geocoding API. Querying coordinates returns a JSON response containing the current location in multiple levels of detail that you could parse.
E.g. for the position lat:40.714224 long: -73.961452, the query URL would look like the following:
http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=false
The result now contains the city and country, beside much more.
You can find more information on the API here: https://developers.google.com/maps/documentation/geocoding/
You could also try http://openweathermap.org/
I haven't used this extensively but I tried it enough that I know it works. It lets you query by location name or geographic coordinates, and the city name is included in the responses along with plenty of other data.
http://api.openweathermap.org/data/2.5/weather?lat=xx&lon=xx returns a weather object with city name & related data. API key is even optional so you can try it out very quickly.
How do mobile apps like yelp and gasbuddy find a list of nearby restaurants/gas stations? I am creating an Android app and have a list of locations in my database. I want to give the user all the nearby locations from my database based on the user's current location. What is the best way to go about it? I am using Java.
Some databases actually have this built in; for example here's a StackOverflow question about spatial queries in Postgres, which should set you on the right path. Your app would send coordinates to a server, which would use those coordinates to query a postgres database directly.
This link may be helpful http://www.dreamincode.net/forums/topic/92885-distance-between-2-points/
when you get the distance just compre it with if or whatever you want and then show it or save.
For getting Geographical Position of a user we have so many API's can any one tell me what is the concept behind this? How these api's can detect the geographical co ordinates of a user.
Please Explain
Thanks and Regards,
Sunny.
This depends entirely upon the API.
Some APIs are dependent on a piece of hardware (such as a smartphone) that utilizes an inbuilt GPS.
Other APIs attempt to use WiFi and/or IP data to attempt a crude calculation for your location. Google's MyLocation feature is an example of this, it uses information gathered by your browser to estimate your location. Here's a link to an article discussing Google's use of WiFi/IP to calculate users positions:
Google MyLocation
Others such as Google, Bing, or ESRI map based APIs allow you to query their maps to receive coordinate information about a specific address that the user inputs. If you already know users are going to access your application from a relatively small geographic area, you can submit the query on their behalf and use it to create a map based on this area (ie: a city, college campus, etc...), or to obtain a set of geographic coordinates when all you have are the addresses (ie: a list of restaurants, apartments, etc...).
Any particular API that you are talking about?
As far as I know, there are 2 ways in general
GPS-enabled devices: So the device itself that know its own geolocation through it's GPS system
Through who you are connected to: a) If you are mobile device, they can pinpoint your location through figuring out the towers you are connected to, or b) If you are on an internet / wi-fi connection, it can be figured out from there.
http://www.ehow.com/how-does_4965061_gps-work-mobile-phones.html
or
How does GPS in a mobile phone work exactly?