Can't get address from Mapbox FeatureCollection - java

I am getting a featurecollection returned from mapbox. The JSON looks like the following:
{"type":"FeatureCollection","query":["17","green"],"features":[{"id":"address.8882296350520732","type":"Feature","place_type":["address"],"relevance":1,"properties":{"accuracy":"rooftop"},"text":"Green Street","place_name":"17 Green Street, Brookline, Massachusetts 02446, United States","center":[-71.121411,42.343136],"geometry":{"type":"Point","coordinates":[-71.121411,42.343136]},"address":"17","context":[{"id":"postcode.8198763973790210","text":"02446"},{"id":"place.7864891969924050","wikidata":"Q49142","text":"Brookline"},{"id":"region.6776276020561540","short_code":"US-MA","wikidata":"Q771","text":"Massachusetts"},{"id":"country.9053006287256050","short_code":"us","wikidata":"Q30","text":"United States"}]},{"id":"address.2730621404747834","type":"Feature","place_type":["address"],"relevance":1,"properties":{"accuracy":"rooftop"},"text":"Greenough Circle","place_name":"17 Greenough Circle, Brookline, Massachusetts 02445, United States","center":[-71.125244,42.334561],"geometry":{"type":"Point","coordinates":[-71.125244,42.334561]},"address":"17","context":[{"id":"postcode.7679295126168220","text":"02445"},{"id":"place.7864891969924050","wikidata":"Q49142","text":"Brookline"},{"id":"region.6776276020561540","short_code":"US-MA","wikidata":"Q771","text":"Massachusetts"},{"id":"country.9053006287256050","short_code":"us","wikidata":"Q30","text":"United States"}]},{"id":"address.4738306377365208","type":"Feature","place_type":["address"],"relevance":1,"properties":{"accuracy":"interpolated"},"text":"Greenleaf Street","place_name":"17 Greenleaf Street, Boston, Massachusetts 02115, United States","center":[-71.090477,42.338387],"geometry":{"type":"Point","coordinates":[-71.090477,42.338387],"interpolated":true},"address":"17","context":[{"id":"neighborhood.295553","text":"Fenway"},{"id":"postcode.11169253348388930","text":"02115"},{"id":"place.9391334652012190","wikidata":"Q100","text":"Boston"},{"id":"region.6776276020561540","short_code":"US-MA","wikidata":"Q771","text":"Massachusetts"},{"id":"country.9053006287256050","short_code":"us","wikidata":"Q30","text":"United States"}]},{"id":"address.2688910343185888","type":"Feature","place_type":["address"],"relevance":1,"properties":{"accuracy":"point"},"text":"Greenwich Street","place_name":"17 Greenwich Street, Roxbury Crossing, Massachusetts 02120, United States","center":[-71.083751,42.335527],"geometry":{"type":"Point","coordinates":[-71.083751,42.335527]},"address":"17","context":[{"id":"neighborhood.295329","text":"South End"},{"id":"postcode.7229336676579040","text":"02120"},{"id":"place.2024861849164830","wikidata":"Q20138","text":"Roxbury Crossing"},{"id":"region.6776276020561540","short_code":"US-MA","wikidata":"Q771","text":"Massachusetts"},{"id":"country.9053006287256050","short_code":"us","wikidata":"Q30","text":"United States"}]},{"id":"address.4057524105398816","type":"Feature","place_type":["address"],"relevance":1,"properties":{"accuracy":"rooftop"},"text":"Greenwich Park","place_name":"17 Greenwich Park, Boston, Massachusetts 02118, United States","center":[-71.080331,42.342747],"geometry":{"type":"Point","coordinates":[-71.080331,42.342747]},"address":"17","context":[{"id":"neighborhood.294804","text":"Back Bay"},{"id":"postcode.8640649655199430","text":"02118"},{"id":"place.9391334652012190","wikidata":"Q100","text":"Boston"},{"id":"region.6776276020561540","short_code":"US-MA","wikidata":"Q771","text":"Massachusetts"},{"id":"country.9053006287256050","short_code":"us","wikidata":"Q30","text":"United States"}]}],"attribution":"NOTICE: © 2019 Mapbox and its suppliers. All rights reserved. Use of this data is subject to the Mapbox Terms of Service (https://www.mapbox.com/about/maps/). This response and the information it contains may not be retained. POI(s) provided by Foursquare."}
The JSON output contains a FeatureCollection. Within the feature array, each feature has a property "place_name" which gives the full address of whatever place is listed. This is what I want to access.
Whenever I read this JSON into my android app and try to convert it to a FeatureCollection, I find that the "place_name" property is not part of a com.mapbox.geojson.Feature. I am using the following to convert the JSON to a FeatureCollection:
FeatureCollection.fromJson(response);
Where response is the returned JSON shown above. My question is: How do I access that property if MapBox does not include it as part of their com.mapbox.geojson.Feature? Is there some other class I should be using that is included by Mapbox?

You could add that property to a feature before creating the collection:
Feature feature = new Feature().fromJson(response);
feature.addStringProperty("place_name", "17 Green Street, Brookline, Massachusetts 02446, United States");
FeatureCollection.fromFeature(feature);
Then, for querying:
feature.getProperties() to get all the properties associated with that feature, or feature.getStringProperty("place_name") to get a specific one.
Take a look at the Features api.

Related

Java check if specific date is public holiday by country

In my java application (spring boot), I'm trying to check if a specific date for Malaysia is a public holiday or not and the challenge is each state has its own Regional holidays on top of the national public holidays which has to be considered.
So my question is that can I do such a thing using Google Calendar API?
I've found this Post but I'm not sure if that would do what I'm trying to achieve.
I've combined some public resources and I'd do that this way:
You want to call for a calendar with id: en.malaysia#holiday#group.v.calendar.google.com
Call:
GET https://www.googleapis.com/calendar/v3/calendars/{calendarId}
Authorisation:
This request requires authorization with at least one of the following scopes (...): https://www.googleapis.com/auth/calendar.readonly or https://www.googleapis.com/auth/calendar
--Api
--StackOverflow answer
--List of supported national calendars

Android - Get id from Geocoder location

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"?

Training Stanford NER failed

I'm still new to the recognition process and still trying to learn more about it.
I have a project where I need to recognize: Table names, People, Departments.
I tried using Stanford NER with it's 3 class and it did recognize people names.
For the department names I tried to train the NER to recognize the departments as organizations. As I found no result on how to create a new annotation for them.
I did follow the instruction from their website.
First I did create a txt file with the following content:
Ahmad works in Customer Service department. The department name is
Customer Service. It has started in 1997, it was called Customer
Service since then. Customer Service has one manager and many
employees. The number of Customer Service department is 1122D. Ahmad
works in Development department. The department name is Development.
It has started in 1997, it was called Development since then.
Development has one manager and many employees. The number of
Development department is 1122D. Ahmad works in Finance department.
The department name is Finance. It has started in 1997, it was called
Finance since then. Finance has one manager and many employees. The
number of Finance department is 1122D. Ahmad works in Human Resources
department. The department name is Human Resources. It has started in
1997, it was called Human Resources since then. Human Resources has
one manager and many employees. The number of Human Resources
department is 1122D. Ahmad works in Marketing department. The
department name is Marketing. It has started in 1997, it was called
Marketing since then. Marketing has one manager and many employees.
The number of Marketing department is 1122D.
Then I used these commands:
java -cp stanford-ner.jar edu.stanford.nlp.process.PTBTokenizer corpus.txt > corpus.tok
perl -ne 'chomp; print "$_\tO\n"' corpus.tok > corpus.tsv
java -cp stanford-ner.jar edu.stanford.nlp.ie.crf.CRFClassifier -prop corpus.prop
Then I got the following error:
CRFClassifier invoked on Mon Dec 01 09:38:10 AST 2014 with arguments:
-prop corpus.prop
argsToProperties could not read properties file: null
Exception in thread "main" edu.stanford.nlp.io.RuntimeIOException: java.io.IOException: Unable to resolve "corpus.prop" as either class path, filename or URL
at edu.stanford.nlp.util.StringUtils.argsToProperties(StringUtils.java:879)
at edu.stanford.nlp.util.StringUtils.argsToProperties(StringUtils.java:818)
at edu.stanford.nlp.ie.crf.CRFClassifier.main(CRFClassifier.java:2869)
Caused by: java.io.IOException: Unable to resolve "corpus.prop" as either class path, filename or URL
at edu.stanford.nlp.io.IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(IOUtils.java:448)
at edu.stanford.nlp.util.StringUtils.argsToProperties(StringUtils.java:866)
... 2 more
How can I train the classier properly?
Many Thanks
UPDATE:
Here is my .prop file
#location of the training file
trainFile = /Users/ha/stanford-ner-2014-10-26/corpus.tsv
#location where you would like to save (serialize to) your
#classifier; adding .gz at the end automatically gzips the file,
#making it faster and smaller
serializeTo = dept-model.ser.gz
#structure of your training file; this tells the classifier
#that the word is in column 0 and the correct answer is in
#column 1
map = word=0,answer=1
#these are the features we'd like to train with
#some are discussed below, the rest can be
#understood by looking at NERFeatureFactory
useClassFeature=true
useWord=true
useNGrams=true
#no ngrams will be included that do not contain either the
#beginning or end of the word
noMidNGrams=true
useDisjunctive=true
maxNGramLeng=6
usePrev=true
useNext=true
useSequences=true
usePrevSequences=true
maxLeft=1
#the next 4 deal with word shape features
useTypeSeqs=true
useTypeSeqs2=true
useTypeySequences=true
wordShape=chris2useLC

Does google libphonenumber API provide CITY name based on the area code?

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"

Google Directions API and Using maps.google.com give different Response

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.

Categories

Resources