How can you find a particular area's police station nearest to a Geo point in android? I set types = type of place to search types = "police"; but no results were found. However, when I set types = "pharmacy";,types = "hospital"; it works properly. i have use this tutorial. Does anyone have any ideas about this?
the project you are referring to is working just perfectly. The Only possible solution I can come up with is that 'there may be no 'POLICE STATION', within the give radius. Try increasing the radius, in the above sample;
change this:
double radius = 1000;
which come under the LoadPlaces AsyncTask.
Related
I am creating an app that has a features that needs to find supermarkets that are in a 5km range from the user.
I thought that using longitude and latitude would be a good idea (I should store those two values as atributes on a supermarket table and I'd be ready to go).
Once I created my table and inserted it's values, I went to look for a solution on how could I get those supermarkets from my database.
What I had in mind would be a select with a not so complex WHERE clause that would solve all my problems. Instead, I found a bunch of different ways of doing it:
1) Create an square around the user location, find the supermarkets that are inside of it and then find the ones that are actually in that range
2) Create extra coluns on your table
3) Use the cosine law
4) Find out how to convert latitude/longitude to kilometers and use Pythagorean Theorem (for ranges that are not so wide)
The three problems are that any solution is made on the database (with a where clause), I have no idea which one has more performance or is better in any aspect and it's not like I'm getting how to use those exemples. So... What should I use remembering that I have and SQLite database and android?
Thanks :)
ADDING MORE INFORMATION:
The first problem was to know which one I should use.
The problem I had with this one was the this:
My user location is:
longitude = -22.82753105;
latitude = -47.03398022;
My where statement
WHERE latitude < -47.078946300295925 AND
latitude > -46.989014139704054 AND
longitude > -22.76155626735494 AND
longitude < -22.89350583264506
I have a market on my database which location is the same the user and I do get a list with this very element once I select the ones that are in the square, but when I iterate on my list, it removes my element from the list bacause the if return FALSE.
if (getDistanceBetweenTwoPoints(mercado, userLocation) <= RANGE)
On the getDistanceBetweenTwoPoints, if I debug it, I get:
dLat = -0.4224822382331485
dLon = 0.4224822382331485
lat1 = -0.39841557692373836
lat2 = -0.8208978151568869
a = 0.07157979929009457
c = 0.5416864422451098
d = 3451084.323543594
And since the if compares "d" with range, it's like this:
if(3451084.323543594 <= 5000) { //my range is 5km
// keep element
else
// remove it from list
Does anyone can tell me what is the problem??
How to find distance from polyline in google map in android using map apiV2 ? I want to find distance when user start moving from one location to another .
I used the Calculate distance in meters when you know longitude and latitude in java but it takes distance between two lat-long not as per user
moves in map. Please help me if anyone knows how to find distance using polyline.
For finding distance from your polyline you can use PolyUtil class which contains one method distanceToLine .
implementation'com.google.maps.android:android-maps-utils:0.5+'
add this library in your build.gradle.
For more you can use Google map utility class
https://developers.google.com/maps/documentation/android-api/utility/
For this you need to use thread. In that at regular interval you should find the distance between current coordinates and last saved coordinate.
Raw code:
Coordinate current, last;
Distance D = 0;
while (true) {
wait(10000);
last = current;
current = getNewCordinate;
d = D + distFrom(current, last);
}
This logic will help.
Based on the answer given by Gevaria Purva I found a more appropriate method on PolyUtil named isLocationOnPath.
For the third parameter most likely you want to pass true.
i have developed an application that interacts with google places api to search for cafe in the neighborhood of a user. for the purpose of my application i want to have the radius set to a very small value.. may be 20 to 50 meters. currently my app is working but its not working the way it should.
In my app, i have set the radius to 350 meters. so practically it should return me the list of cafe that fall in the radius of 350m. however my app still shows starbucks in this result set even if starbucks is 650m (road distance) and 500m (straight distance). I would like to know what should be done to get the correct results.
Currently i am using GPS for this. will a combination of gps and network service provide me a better reading?
public PlacesList search(double latitude, double longitude, double radius, String types)
throws Exception {
this._latitude = latitude;
this._longitude = longitude;
this._radius = radius;
this question is not related to Android, but to the Google Places API.
are you using place search or text search? both of them have comments regarding location biasing
text search:
"You may bias results to a specified circle by passing a location and a radius parameter. This will instruct the Place service to prefer showing results within that circle; results outside of the defined area may still be displayed."
place search:
"distance. This option sorts results in ascending order by their distance from the specified location. Ranking results by distance will set a fixed search radius of 50km. One or more of keyword, name, or types is required."
I am developing an application that shows the distance between the user and multiple locations (such as foursquare in the image below) on android, I am using eclipse and would like to know how to calculate the distance between various points. Thank you!
Image:
http://i.stack.imgur.com/rsWmO.jpg
There are probably many ways to get this done, here's an option.
You could use the distanceTo() method. If you want more than one distance, simply use a loop to repeat it until you've calculated the distances between all the Locations you have at hand.
If you're using Google Maps, you can use a Distance Matrix
https://developers.google.com/maps/documentation/distancematrix/
https://developers.google.com/maps/documentation/javascript/distancematrix
Here I am providing you some sample code for Distance calculation. I have done like this in my project. Here distanceTo() method will return you the distance in double.
private Location currentLocation, distanceLocation;
double distance = 0;
//set your current location
currentLocation.setLatitude(currentLat);
currentLocation.setLongitude(currentLong);
//set your destination location
distanceLocation = new Location("");
distanceLocation.setLatitude(destinatioLat);
distanceLocation.setLongitude(destinationLong);
distance = currentLocation.distanceTo(distanceLocation)/1000;
Same for more then one location you can use Array for storing distance. Its on you how you want to use it as per your requirement.
Hope this will help you.
Hi
I am having a little trouble figuring out how to convert between types of coordinates. I have a list of coordinate sets with the following description
"Coordinates are always in the WGS84 system. All coordinates a represented as integer
values x and y where the coordinate value is multiplied with 1,000,000."
An example:
559262 6319512
Well, I need to convert these to long/lat (and back) so i can use these in google maps (android). But this is not as easy as it seams. I have been searching around and did find some code to do this, but it does not seam to work properly. Anyone who can provide some code for doing this? If possible, I would like to avoid a big geo framework (it has to be used in an android application).
thanks.
best regards, kenneth
EDIT:
I did find a solution on my own. I downloaded the class described here:
http://www.ibm.com/developerworks/java/library/j-coordconvert/
And it works fine. Hope someone can find it useful.
I am sorry for posting before having done my homework decently. Thanks to everyone who posted
If you're getting the location from the GPS on android, you will get a Location object that holds Lat/Long as doubles. In order to display a point on Google Maps, you need to turn these double values into a GeoPoint object using:
GeoPoint location = new GeoPoint(
(int) (mLocation.getLatitude()) * 1E6),
(int) (mLocation.getLongitude()) * 1E6)
);
Hope thats helpful.
All GPS systems give their latitude and longitude with respect to the WGS84 model of the Earth. Unless you intend to give the lat/lon with respect to a nation's local model, such as the British OSGB36 model, you should be fine treating the coordinates you have as representing microdegrees. Even here in the Britain, the Admiralty now print their nautical charts with lat/lon relative to WGS84, I expect the Ordnance Survey land maps will follow suit soon, if they haven't already done so.