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"
Related
I need to write a rule using Drool that will validate that the phone number is valid US number (for the sake of this answer we can use this regex "^([0-9]{3})[0-9]{3}-[0-9]{4}$")
The object structure is like this:
{
"name": {"firstName":"John", "lastName":"Smith"},
"phone": [{"phoneType": "mobile", "phoneNumber":"123456789"}],
"dob":"01/01/2000"
}
Because phone is a list, I don't know how to loop and validate this object. For instance the validation for "dob" field looks something like this:
rule "RuleId: Drool01, Validate dob"
when
$user: user(dob != null)
user(dob not matches "(?:0[1-9]|1[012])" from $user
then
modify($user){setDob(null)};
I appreciate any help on this. I apologize if this is very basic but I literally just started to use Drools.
I'm going to assume these models (irrelevant bits omitted; assume getters and setters):
class User {
private Name name; // Name model not shown, not relevant to this question
private Phone phone;
private String dob;
}
class Phone {
private String phoneType;
private String phoneNumber;
}
We can then write a rule like this:
rule "Invalid Phone Number"
when
$user: User( $phoneNumbers: phone )
exists( Phone( phoneNumber not matches "^([0-9]{3})[0-9]{3}-[0-9]{4}$" ) from $phoneNumbers)
then
// $user has at least 1 phone number which doesn't match the pattern
end
This rule is useful when we only need to know that there exists a bad value. It gets a little more interesting if we actually need to get those bad values (eg. if we want to report out a better error message.)
If we want to trigger the consequences for each bad phone number (eg. if there are 3 phone numbers and 2 are bad, we want to trigger the "then" twice) we could do like this:
rule "Invalid Phone Number - trigger for each"
when
$user: User( $phoneNumbers: phone )
$badPhone: Phone( phoneNumber not matches "^([0-9]{3})[0-9]{3}-[0-9]{4}$") from $phoneNumbers
then
// here $badPhone will be a phone number for $user that doesn't match the pattern
end
You might want to write a rule like this if you want to do something for each bad phone number individually. Consider maybe if we were doing "verified" phone numbers -- for example, they text you passcode that you have to use to verify your phone number; in this case you could text each phone number, one-by-one, to go through this verification process.
Alternatively we could just collect up all of the bad phone numbers and trigger the consequences once for all of those numbers, collectively.
rule "Invalid Phone Number - trigger once for all"
when
$user: User( $phoneNumbers: phone )
$badNumbers: List( size > 0 ) from collect (
Phone( phoneNumber not matches "^([0-9]{3})[0-9]{3}-[0-9]{4}$") from $phoneNumbers
)
then
// $badNumbers is a list of all of the Phone objects that don't match
// the pattern and belong to $user
end
I use this tutorial : Using OpenWeatherMap API Key
When I use this url with the city name the name is correct. So if I put "Paris" I have the word "Paris" on my application:
URL url = new URL("http://api.openweathermap.org/data/2.5/weather?q="+city+"&APPID=ea574594b9d36ab688642d5fbeab847e");
But when I try to do the same thing with latitude and longitude instead of the name of the city. The data of temperature, wind, pressure, ... are right. There is just the name of the city that is not right. Instead of having "Paris" I have something else.
URL url = new URL("http://api.openweathermap.org/data/2.5/weather?lat=%s&lon=%s&APPID=ea574594b9d36ab688642d5fbeab847e");
Example, by entering this into the browser. The numbers are reduced to two digits after the decimal point.
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 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.
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.