Populate a ListView with GeoPoints near me - android

I have a table at Parse.com full of addresses of places.
Every row contains the name of the address, and a GeoPoint (Latitude and Longitude).
I want to do 2 things:
1. Populate a ListView with data from my table (name and address), but places that are not further than, for example, 500 meters;
2. Convert the GeoPoint to an address (Street, City), so every ListView item will be shown like this:
Address Name
Street (with number of the house), City.
Can you please help me?

I found an answer for my first question. I've added that code in the activity AsyncTask on the doInBackground method.
Use this guide, together with
query.whereWithinKilometers("Location", geoPoint, 1.5);

Related

Find custom near locations

I have a table with the following fields:
Name Longitude Latitude
The user can search for near places depending on the radius he chooses, what is the algorithm used to do this?
Example: I retrieve the user Longitude/Latitude, and I ask him about the radius in KM he wants to apply to his search, then these 3 parameters should be sent to the method that will retrieve the location.
I found the answer.
In other words what we need is the distance between two points that we have their coordinates, so using math :
Distance between two points

How to sort listview according to a specific listview item

I am basically making an application which displays various food stores which are near to user's location.
I have successfully integrated google map but I am not able to filter my list view items according to nearest user location.
For example I have a list view item
place
and its values goes as
place1 , place2, place3, place4 and so on
and I want that if the user location is near to 'Place 1' then user should be shown food items of Place 1 first then Place 2,3 and 4.
So I want to sort list view according to a specific list view item (PLACE) and compare it with the user location and display results which are near to user.
I have no idea to do this.
Thanks in Advance.
You may consider storing all your data in two dimensional ArrayList, so that one of your columns would be "place". Then sort it using the code below and then pass it to the adapter.
ArrayList<ArrayList<String>> yourData = new ArrayList<ArrayList<String>>();
yourData = /* initialize your data */ ;
Collections.sort(yourData, new Comparator<ArrayList<String>>() {
#Override
public int compare(ArrayList<String> row1, ArrayList<String> row2) {
return row1.get(0).compareTo(row2.get(0)); // "at 0 index your place
}
});
UPDATE:
You may store longitude and lattitude values in column "Place" for each restaurant. Then when you get the user's current location, you may launch some method that will calculate the distance between the user and your restaurants. The method may look like this:
float [] distResult = new float[1];
Location.distanceBetween(latA, lonA, latB, lonB, distResult);
float dist = distResult[0];
Store these calculated values in a seperate column. After the all calculations are done, you may call that sort method which will sort items based on the column that contains the distance between user's current location and your restaurants.
For more information about calculating the distance refer to this
Take items in your adapter and sort it. Maybe you would need to extend standard ArrayAdapter for it. And not forget to call Adapter.notifyDataSetChanged() after sort.

Write/Read then Save text file Basic4Android

I'm creating an application on Basic4android that collects GPS coordinates and equipment deficiencies in a dropdown list (Spinner). The GPS coordinates consists of latitude and longitude shows up on a label field when GPS is ON and the deficiencies shows up under a Spinner field (e.g. dropdown of "Broken cross arm", "Broken Insulator","Rusty Structure"). I was able to get all that done and create a "Submit" button that should copy the three fields (Longitude, Latitude and deficiencies) into a text file. Any idea how to store these fields everytime I press submit? I will be using this application for inspection when I walk by a transmission tower, I will record the coordinates and the obvious deficiency into a file on android.
Thank you,
Eli
There are some solutions. one of them is writhing a list file .add a character as delimiter between Longitude, Latitude and deficiencies.
declare list in global section
Dim list1 as list
initialize list on create activity event
List1.Initialize
On submit button click
newstring=longt &"|" &lat &"|"& defi
If File.Exists (File.DirInternal & "/","Log.txt") Then
List1 = File.ReadList (File.DirInternal & "/","Log.txt")
end if
List1.add(newstring)
File.Writelist(File.DirInternal & "/","Log.txt",List1)
You can split every line int to seperated Longitude, Latitude and deficiencies later when you need.
There are several ways to do it. The simplest is to add the values to a Map and use File.WriteMap / ReadMap.
See this tutorial: http://www.basic4ppc.com/android/forum/threads/6690/#content

Android Listview using Google maps

Iam building sample android app . Initially am displaying list with some cities.by clicking on any one of the city it will display map regarding to that city.
now am suffering with how to connect selected city from list with googlemap.any idea please let me know.
You simply make the list of city objects. Each object will contain the name of the city and the location (latitude, longitude). When you click an item, go to a map activity passing the location in the Intent object. In the map activity you'll parse the location and tell the map to go to that point.
Firstly, U have, for example database(or local data structure in your list activity) with cities and corresponding coordinates. Then, in onListItemClick() you create new intent and insert to it's extras necessary data (title, coordinates or primary key of the row in db table). Start new activity extended MapActivity with this intent, take mMapController = mMapView.getController(); and animate to mMapController.animateTo(new GeoPoint((int)yourLatitudeE6,(int)yourLongitudeE6)), where yourLatitudeE6 and yourLongitudeE6 - extras from intent
I think you should have lat and long of city .So you can send that lat and long to mapview through bundle and populate map of that city. In this link you can get complete tutorial for mapview . http://www.vogella.com/articles/AndroidGoogleMaps/article.html

How to get 2 Character Country name using longitude and longitude android?

I can get the longitude and longitude android. And now I want to get the short country name against it. How to do that? I also have country code... All I want is to show short country name e.g "UK" , "SG" etc...
Finally I found a web-service that give 2 digit country code along with temperature.
Its very simple
http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=31.50766766,74.33741188000002

Categories

Resources