Location selector picker input widget - android

What I want to do:
display a text box as an input field, which will accept a city name (any city throughout the world)
as the user starts typing, I'll auto-(complete/suggest) city names.
when the user selects a city name from the dropdown, the name appears in the text box as well, and the background gets highlighted to a very light blue.
Is there any existing widget that does this? If not, what would be a good way to auto-(complete/suggest) city names?
Edit: I know AutoCompleteTextView does autocompletes. The problem is more about dealing with an exhaustive datasource of cities (hopefully available as an API online somewhere), and connecting the widget with this list of datasource.

As you already pointed out yourself, a widget as described could be fairly easily built using standard components in the Android SDK, with the main one being an AutoCompleteTextView. In terms of "where to get the city data from", you basically have two options:
Bundle the data with the app.
Use a webservice.
Both obviously have their pros and cons. Bundling the data will blow up your APK size, a lot, whereas webservices are usually subject to a courtesy limit. Whichever option is the 'best', will depend on several factors, including the size of your app's userbase.
Some concrete resources for bundling the data:
MaxMind's Free World Cities Database (33MB)
GeoNames (233MB!)
And webservices:
GeoNames (cc-by licence, 30k requests/day, 2k requests/hr).
Google Places API - Autocomplete (1k requests/day, or 100k requests/day if you verify your identity with Google, or try your luck and request a higher courtesy quota)
Note that these lists are by no means exhaustive - I'm sure there are plenty of other options. They should offer you a decent starting point though.

You could try the AutoCompleteTextView class
http://developer.android.com/reference/android/widget/AutoCompleteTextView.html

I guess what you are looking for is something similar to Typeahead address picker.
https://github.com/sgruhier/typeahead-addresspicker
It can both recommend autocomplete while you type, and use a map to select/show the address. Looks good :)

Related

Asking for advice of how to appraoch an application

as part of a university project, i have to build an android app that will contain informations about diseases, the diseases will be listed in a list (alphabetic order), when clicked on a disease you'll be directed to another layout that contains informations about the disease chosen (including text and images).
i'm new to this and i don't know how to approach this app..and for the text should i build a database or directly input the text inside the app or something like that .if you know a tutorial or something that would help please share
Ps: there is almost 60 Diseases and each disease will have a subitems (causes, treatment, clinical signs .)
thanks
First of all, the comments are right. Please be more precise in your question. Ask what specific problem occured, if possible provide code samples, errors and research state. https://stackoverflow.com/questions/how-to-ask
UI Design (List)
there is almost 60 Diseases and each disease will have a subitems
Therefore I would suggest an ExpandableListView.
Check out this code sample: https://www.journaldev.com/9942/android-expandablelistview-example-tutorial
Afterwards if the user clicks on an item, you open another Activity with details
Data Storage
should i build a database or directly input the text inside the app or
something like that
Static approach
As you can think of, putting data directly into views makes it difficult to maintain, but is faster implemented and less difficult.
Implemenation: I would suggest putting the data into res/raw as a .json file. In your code, build a JSONObject out of it and pass it to the ListViewAdapter.
Dynamic approach
You need Internet permission, a webserver and a remote database from where you can query the data.
Implementation: If you have a hosted webserver you probably have PHP and MySQL databases. Create a table, fill it with data and build an API in PHP where you provide the data from the database. If you have a VPS or dedicated server you can use MongoDB which works with JSON out of the box.
My guess
For an university project, use static. Otherwise dynamic of course.
Hope this helps

SQLite selection with typo

in my Android app I need to select data from a SQLite database. However, I have a search field in which users can type the name of a location. As they may typo this name, I need to be able to draw the relevant records from the database according to this.
For example:
Input: Ferris Whrrl
Actual: Ferris Wheel
It should locate the Ferris Wheel entry correctly despite the typo. I realise that editdist3 is not implemented in Android SQLite. I'd also rather not select the entire database into RAM and loop through all Strings and calculate Levenshtein distance manually as this would be super resource intensive.
Any help will be greatly appreciated!! :)
I think the best thing you can do is to implement an Auto Suggestion function just like all search engines nowadays do.
You could implement a dynamic algorithm that searches and caches values as needed when a new letter is entered. However, if you just operate on the bare metal without the help of any external service you will have resource problems too - depending on the size of your database and other context variables.
Having a proper index will help but I still think to load the all necessary values into an array and search is faster.
Here you need to create an AI system to guess the correct word. I think this is not relevant to SQL or Android.
Or you can use online AI system to guess the correct word.

What's the proper way of importing option lists into an Android app?

I have been storing option lists for my Android app in a cloud table. For example, categories like "historical fiction","biography","science fiction", etc. I see the following pros and cons:
Pro:
I can make changes to the list without sending an app update to Google Play
Not normalized - I can use the text in my other data tables instead of a reference ID
Con:
App needs to take time to download from the web each time (or at least check for changes)
English only
I believe the "proper" way to do this is the use the XML resource files. But I need to make sure the selection references correctly with my data. That is, my app needs to understand that "Poetry" and "Poesía" are the same thing.
Is the correct thing to do:
Forget about it since I'll never get to the point where I'm translating my app anyway
Use a string-array and use the index (0...x) to know what the selection is
Use a 2-dimensional string-array with a reference ID in the first column and the text in the second?
If you are handling the category list online, then why not handle the translations online as well. Here is what I would suggest:
In your application options, have a list of supported languages (each in their native translation). These language options should be stored on whatever server application is handling your web requests. Each language is associated with an integer ID that the user does not see, but is stored in the app.
Whenever you issue a web request to get a list of options, include the language id in the message. This will allow you to know what language the user has picked and can use a 2D array or some other structure to handle the conversion to and from the chosen language.
I'm not sure if this helps at all, since I don't know exactly what you are making or how you are designing it, but from the given description, this is an easy and effective course of action.

Best approach for android autocomplete search box

I would like any suggestions on how to implement a fast autocomplete search box on android.
Useful info:
1) Data will be stored locally on phone memory. No database or network should be needed.
2) There is no restriction on the type of file that will be used. Could be simple text file, XML file, or whatever suits best.
3) The file will contain a large amount of records that are distinguished by a unique ID/CODE.
There will be also a human readable name for the record and a text with more info on the record like
CODE: HUMAN_REPRESENTATION: EXTRA_INFO:
AF32 Orange The orange (specifically, the sweet orange) is the fruit of the citrus species Citrus...
AF33 Apple The apple is the pomaceous fruit of the apple tree...
4) The user will type on the text area the HUMAN_REPRESENTATION string he wants, and he will be shown a list of matching records to select of.
5) While typing he should be given auto-complete suggestions so he would not have to type the exact phrase.
6) The amount of records will be about 15,000.
So which is the best way to store and retrieve data as fast as possible?
What file type would you suggest? Should the data be split into many files? Can I use a specific API?
I would really be thankful for any directions here, as I am new in android development, but experienced in desktop applications.
EDIT :
Since I had no answers in many days, I would like to know if my question is not clear enough or if it has already been answered. Please comment.

getting multiple marker coordinates in google map android

Hi to all the members of this great community!
This is my first question so forgive me for possible mistakes. I hope that from this day on i can be helpful for some of you as hopefully you will be for me.Getting to the question:
I am building an android app whose purpose is to search for nearest fuel-points and nearest care-repair-centers. I am very new to android and thx to the numerous posts about android in here I have managed to reach the point where i have build the map and animate it to my current location while updating my location.
Now i have to add the markers of the points of interest. Since they are at least 10 (I will add them only for demonstration purposes) i think it's not wise to add them through 10+ repetitive calls to itemizedOverlay.addOverlayItem(). My idea was to save them in a file in the format ( " latitude " , "longitude" , simple_description_title , other info ) and than in some way import the first 2 fields for the geopoint and the 3rd for the title.
I will use than the 4th later for some type of tooltip text (for example tel_number).
Do you think this is a good approach? And how can I implement the file reading(if) in the code that extends ItemizeOverlay().
I didn't post the code until this point since it's irrelevant.
Welcome to SO, let's jump right into your problem/question.
1.) Since you are only adding 10 points of interest it won't matter if you just call itemizedOverlay.addOverlayItem() for all 10 because the trick is to call itemizedOverlay.populate() only after you have added all the overlayItems using itemizedOverlay.addOverlayItem(), this way you don't compromise on performance.
2.) Now, once again, since you are only doing a demonstration I would advise you to simply hard-code all the 10 overlays with their respective geolocations into the Android code itself. This way you WON'T have to worry about reading data. Also, using a txt file to store data isn't the best option both performance and convenience wise. This is what databases exist for.
3.) If, and when you do this in the future, you do need to use some dynamic data to populate your markers with, then I'd STRONGLY advise you to use either
SQLite: The embedded database that Android offers, it's great for storing small bits of information that's required for your application such as description title, other info, the latitude, longitude, however, if you have some sort of a connection based application where you need to update globally accessible data every once in a while I'd advise you to use the next option,
MySQL: This is an online database that you have to interface with using a server and PHP. The advantage of using an online database is that you can now share information between different users (friends, contacts, followers etc.) by reading and writing to and from the database.

Categories

Resources