I am doing "Address Validation". My Address table has "Street Address", "City", "State", "Postal Code", "Country". I am using Google MAP API to validate my address.
I gave my address like
Street Address -- "kajhfkjdhfkjdsh"
City -- ksjfdlsjflsdjflk
State -- AP
PostalCode -- 500087
Country -- India
In this example only State, PostalCode, Country are valid and the remaining fields are invalid. But when I use the Google Map's API its saying its a valid address. But the street address and city are invalid.
So as per my observation the address validation is done only based on 3 fields those are (State, Postal Code, Country). So How can I validate Street and city along with the remaining fields with GOOGLE MAPS API?
Or is there any way/other (API) to validate all the fields in my address table.
Can anyone help me on this. I am stuck over here.
When trying this address with the google geocoding service http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address=kajhfkjdhfkjdsh,ksjfdlsjflsdjflk,AP,500087,India I see the result is of type postal_code and partial_match is set to true.
Trying real address I get the result type as street_address and the partial_match flag is missing.
I suggest you make some tests and check the content of the service result. This is a geocoding service, so it aims to give you a location to point your map to, not to validate addresses.
Related
I am using Firebase Auth and Firebase Database to store student's profiles and students reports.
When the user signs up they input email, password, school name, school year, school discipline. I use the email and password for the Auth but the rest of the info is stored in the Database with a unique ID as shown below:
For the reports, each students can input many entries, each with its unique ID as shown below:
Here are my questions:
Once a student logs in, how can I find their profile info since the parent is a unique ID. In other words is there a way to search through the database for that students email (for example, mido4#hotmail.com, in the image) and from that get the students name (in this case, Emina Osman)?
Once you get the student's name, how can you search for all the entries that student has saved in the database? For each entry the student has, the student name is saved.
Not sure if the way I setup the database is ideal so is there a better way?
Thanks for your time! Any help would be really appreciated!
Yes, it is. The simplest way to achieve this, is to change your database structure a little bit. So instead of using as a unique identifier, the pushed key, generated by the push() method, i suggets you using the email address. It's also unique and easy to use. The benefit is, that is allows you to search your database for that particular email. Your database structure should look like this:
flashscreen-1d252
|
--- Users
|
--- mido4#hotmail,com
| |
| --- //User Details
|
--- mido5#hotmail,com
|
--- //User Details
Note, that Firebase does not allow symbols as . (dot) to be used in a key. So as you probably see, i have changed the . dot with a , (comma). I have achieved this using the below method:
String encodeUserEmail(String userEmail) {
return userEmail.replace(".", ",");
}
To search for an user and get the name, simply add a listener on Users node like this:
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference userRef = rootRef.child("Users").child("mido4#hotmail,com");
ValueEventListener eventListener = new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()) {
String firstName = dataSnapshot.child("firstname").getValue(String.class);
String lastName = dataSnapshot.child("lastname").getValue(String.class);
Log.d("TAG", firstName + " " + lastName);
}
}
#Override
public void onCancelled(DatabaseError databaseError) {}
};
usersRef.addListenerForSingleValueEvent(eventListener);
The output will be: Emina Osman
You'll have to search after the email address and not after the name.
Already answered above. This database structure is more efficient.
Edit: There 2 additional questions regarding this answer based on using the email address vs. uid.
What if a user decides to delete his account and after a while decides to return and tries to sign-in again? If we are using the email address, nothing happens. If we are using the uid, when the user signs in for the second time, another uid is generated, which is obvious that is different from the first one and this the moment in which you are in trouble, because even he is the same user, he is treated as a new one.
What if the users email address changes? IMHO, an email can be changed only if you decide to change it. Personally, I haven't changed my email address in years but I have deleted hundreds of accounts from hundreds of applications. Even if you change your email address, there's no much of a problem. You login in your application, change the email address and that's it. You'll have also all your history within that application. Having a unique identifier a uid, in case you delete the account and you come back again, you start from zero.
Once a student logs in, how can I find their profile info since the
parent is a unique ID.
Super easy! When a users account is created initially, Firebase assigns the user a 'random' and unchanging user uid (uid). That uid is what identified that specific user to Firebase. That's what you should store there info under within the users node like this:
users
uid_0
name: "users name"
Then when they authenticate in the future, firebase provides that uid to you in the authentication process. You can then simply get their user information from the users node via that uid. i.e. read the node /users/uid_0
Once you get the student's name, how can you search for all the
entries that student has saved in the database?
Again, super simple. For every entry you make in Firebase, reference that uid. For example, say you want to keep track of each users reports
reports
uid_0
-9i9sdjj3i0a09djads //create with push() or childByAutoId() in swift
reportName: "some report"
-ua9sd9i9i3i0idsfi
reportName: "another report"
Then to get all of their reports, read the node /reports/uid_0
conversely, you can store the reports and then a link to the user
reports
-9i9sdjj3i0a09djads
reportName: "some report"
report_by: "uid_0"
and with that structure a query can be done where report_by is equal to "uid_0" to return all of uid_0's reports.
Not sure if the way I setup the database is ideal so is there a better
way?
there's a number of different ways to achieve what you want but the above is a very common design pattern.
UPDATED: If I try to use ZIP CODE I'll get neighborhood code. And I want something to identify NEW YORK not the neighborhood.
I'm using geolocation (geocoder) in my app, and I compare the city name that geocode gives me with a name I already have in my database.
For example, if the user has phone language in English the result would be something like this:
DATABASE: New York
APP RESULT: New York (MATCH)
But if user has phone language in Spanish the result won`t match:
DATABASE: New York
APP RESULT: Nueva York (NO MATCH)
Is there any way to obtain a UNIQUE ID for every CITY instead of names, something like "CITYNAME = 0001q5"?
I am working on google libphonenumber to get the phone number's information. I was able to pull the State & country name. But I am unable to get the CITY name. Does the google API provide CITY name as well ?
Please advice thanks in advance.
Does Google's libphonenumber API provide city names based on the area code?
Yes - but only if its internal geocoding database contains that information. Some US phone numbers are entirely non-geographic (like 1-800 numbers) and for many others the database just doesn't have that information.
Also, libphonenumber's geo lookup only returns single string values: it does not return structured data, like a class with city, state, county, and zip code fields. And the format of the returned string value varies considerably - limiting its uses in any automated system as it necessarily requires a human user to interpret the data.
For example, using the current libphonenumber (as of December 2021, that's version 8.12.38), I get the following results for these fictitious, but valid, numbers:
1-800-333-4567
This is a non-geographic "1-800" (toll-free) number.
libphonenumber's lookup returns the string "United States".
1-201-200-0000
The is is a US phone number in area code 201 for New Jersey.
libphonenumber's lookup returns the string "Jersey City, NJ".
It resolved it to a city and state, giving the state's abbreviation.
1-425-666-9999
This is (almost) my own personal phone number which I got from a T-Mobile store in Redmond, WA.
But libphonenumber's lookup returns only the imprecise string "Washington State" with no city name or similar. It's curious that it returned the full US state name instead of the "WA" abbreviation.
Remember, as with any in-proc "offline" geolocation database, data will inevitably go stale and inaccurate. Also, in the US at least, it's impossible to differentiate between mobile-phone numbers and landline numbers, and the area-code of someone's mobile-phone number is completely detached from the phone subscriber's actual physical location (it's usually the area-code of the AT&T / T-Mobile / Sprint store where they initially signed-up for service, even if they subsequently move across the country).
Anyway, here's how you use the PhoneNumberOfflineGeocoder class:
Java:
static string lookupNumber( string phoneNumber ) {
PhoneNumber parsed = PhoneNumberUtil.getInstance().parse( phoneNumber, /*defaultRegion:*/ "US" );
return PhoneNumberOfflineGeocoder.getInstance().getDescriptionForNumber( parsed, Locale.ENGLISH );
}
lookupNumber( "1-800-333-4567" ) // "United States"
lookupNumber( "+12012000000" ) // "Jersey City, NJ"
lookupNumber( "+14256669999" ) // "Washington State"
C#
static String LookupNumber( string phoneNumber ) {
PhoneNumber parsed = PhoneNumberUtil.GetInstance().Parse( phoneNumber, defaultRegion: "US" );
return PhoneNumberOfflineGeocoder.GetInstance().GetDescriptionForNumber( parsed, Locale.English );
}
LookupNumber( "1-800-333-4567" ) // "United States"
LookupNumber( "+12012000000" ) // "Jersey City, NJ"
LookupNumber( "+14256669999" ) // "Washington State"
Here - > https://maps.google.com/
I queried for parameters
A : antim chauraha, Indore, Madhya Pradesh, India
B : India Collection, Indore, Madhya Pradesh, India
And using the webservice to get as XML, same response from Direction API
http://maps.googleapis.com/maps/api/directions/xml?origin=ANTIM%20CHAURAHA,Indore,Madhya%20Pradesh,India&destination=INDIA%20COLLECTION,PALSIKAR,Indore,Madhya%20Pradesh,India&sensor=false
Those responses do not match at all. You see the distance, direction or anything.
Am I doing something wrong?
Google Maps uses additional information to locate your "query string". The directions API uses postal addresses (for the most part).
Neither of these looks like a particularly good "address"
A : antim chauraha, Indore, Madhya Pradesh, India
B : India Collection, Indore, Madhya Pradesh, India
Run them through the Google Maps API v3 geocoder, they both resolve to the same place (Indore, Madhya Pradesh, India)
If you need to resolve "places" like that, use the Places API to get coordinates, then use the directions service to get directions between the coordinates.
Basically there is a difference in name and address. Google database can have other symbols for the same location. You can read my answer here: http://www.stackoverflow.com/questions/12788664/google-maps-api-geocode-returns-different-co-ordinates-then-google-maps/12790012#12790012. In the google response the name is what you are looking for and in the placemark object the list of address and location in the google database. You need to loop through the placemark object to find the most similar location.
Im trying to create a Business card reader
Im having a block of text for example
Name
Head - Business Development
Company Name
# 2/324, ll Floor, Some Road,
Street, City-Zip, State, Country.
Tel : +987654321
Mobile: +123456789
Email : mail#comany.com
Website : www.comany.com
I want to parse the details out of this text like name, company name, designation, address. I was able to parse number, email address and website. Can anyone help me with it. I dont want to use any webservices, I want it to be done offline.
I was able to parse number, email address and website
How are you doing it? What problems are you facing in parsing other parts?
If the sequence of contents is not going to change, simply read line by line and parse accordingly.
You can look at StringTokenizer.