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