Wikidata prevent fallback languages - sparql

I query some cities with their names .
This works fine. Now when I look at this : https://www.wikidata.org/wiki/Q729978
I can see there is no spanish name but i get "Mediolanum"
Why do I get there a value? and how can i change it ?
Here my query
SELECT DISTINCT ?city ?label ?population WHERE {
VALUES (?city) { (wd:Q729978) }
?city rdfs:label ?label
FILTER(LANG(?label) IN ("de","en","es","fr","it","pl","cs","hr","hu","nl","ru","tr","ro"))
}
The response is
{
"head" : {
"vars" : [ "city", "label", "population" ]
},
"results" : {
"bindings" : [ {
"city" : {
"type" : "uri",
"value" : "http://www.wikidata.org/entity/Q729978"
},
"label" : {
"xml:lang" : "de",
"type" : "literal",
"value" : "Mediolanum"
}
}, {
"city" : {
"type" : "uri",
"value" : "http://www.wikidata.org/entity/Q729978"
},
"label" : {
"xml:lang" : "en",
"type" : "literal",
"value" : "Mediolanum"
}
}, {
"city" : {
"type" : "uri",
"value" : "http://www.wikidata.org/entity/Q729978"
},
"label" : {
"xml:lang" : "nl",
"type" : "literal",
"value" : "Mediolanum"
}
}, {
"city" : {
"type" : "uri",
"value" : "http://www.wikidata.org/entity/Q729978"
},
"label" : {
"xml:lang" : "es",
"type" : "literal",
"value" : "Mediolanum"
}
}, {
"city" : {
"type" : "uri",
"value" : "http://www.wikidata.org/entity/Q729978"
},
"label" : {
"xml:lang" : "fr",
"type" : "literal",
"value" : "Mediolanum"
}
}, {
"city" : {
"type" : "uri",
"value" : "http://www.wikidata.org/entity/Q729978"
},
"label" : {
"xml:lang" : "hu",
"type" : "literal",
"value" : "Mediolanum"
}
}, {
"city" : {
"type" : "uri",
"value" : "http://www.wikidata.org/entity/Q729978"
},
"label" : {
"xml:lang" : "it",
"type" : "literal",
"value" : "Mediolanum"
}
}, {
"city" : {
"type" : "uri",
"value" : "http://www.wikidata.org/entity/Q729978"
},
"label" : {
"xml:lang" : "hr",
"type" : "literal",
"value" : "Mediolan"
}
}, {
"city" : {
"type" : "uri",
"value" : "http://www.wikidata.org/entity/Q729978"
},
"label" : {
"xml:lang" : "ru",
"type" : "literal",
"value" : "Медиоланум"
}
} ]
}
}

Related

Unable to create index in Elastic search using API

I am trying to create index in Elasticsearch using API using the following mapping in kibana dev tools. Once I create the index, I want to use reindex API to copy documents from an already existing index.
PUT /ipflow-logs
{
"ipflow-logs" : {
"mappings" : {
"properties" : {
"conn_state" : {
"type" : "keyword"
},
"content_length" : {
"type" : "long"
},
"content_type" : {
"type" : "keyword"
},
"createdDate" : {
"type" : "keyword"
},
"dst_ip" : {
"type" : "ip"
},
"dst_port" : {
"type" : "long"
},
"duration" : {
"type" : "long"
},
"history" : {
"type" : "keyword"
},
"local_orig" : {
"type" : "keyword"
},
"missed_bytes" : {
"type" : "long"
},
"orig_bytes" : {
"type" : "long"
},
"orig_ip_bytes" : {
"type" : "long"
},
"orig_pkts" : {
"type" : "long"
},
"protocol" : {
"type" : "keyword"
},
"resp_bytes" : {
"type" : "long"
},
"resp_ip_bytes" : {
"type" : "long"
},
"resp_pkts" : {
"type" : "long"
},
"service" : {
"type" : "keyword"
},
"src_ip" : {
"type" : "ip"
},
"src_port" : {
"type" : "long"
},
"timestamp" : {
"type" : "date",
"format" : "yyyy-MM-dd 'T' HH:mm:ss.SSS"
},
"uid" : {
"type" : "keyword"
}
}
}
}
}
I am getting the below error when I try to create the index.
"type": "parse_exception", "reason": "unknown key [ipflow-logs] for create index", "status": 400
Any help is appreciated. Thanks
You need to do it this way (i.e. mappings should be at the top):
PUT /ipflow-logs
{
"mappings": {
"properties": {
"conn_state": {
"type": "keyword"
},
"content_length": {
"type": "long"
},
"content_type": {
"type": "keyword"
},
"createdDate": {
"type": "keyword"
},
"dst_ip": {
"type": "ip"
},
"dst_port": {
"type": "long"
},
"duration": {
"type": "long"
},
"history": {
"type": "keyword"
},
"local_orig": {
"type": "keyword"
},
"missed_bytes": {
"type": "long"
},
"orig_bytes": {
"type": "long"
},
"orig_ip_bytes": {
"type": "long"
},
"orig_pkts": {
"type": "long"
},
"protocol": {
"type": "keyword"
},
"resp_bytes": {
"type": "long"
},
"resp_ip_bytes": {
"type": "long"
},
"resp_pkts": {
"type": "long"
},
"service": {
"type": "keyword"
},
"src_ip": {
"type": "ip"
},
"src_port": {
"type": "long"
},
"timestamp": {
"type": "date",
"format": "yyyy-MM-dd 'T' HH:mm:ss.SSS"
},
"uid": {
"type": "keyword"
}
}
}
}

Invalid Schema Update during patch operation on existing table in Google BigQuery via Google API Client

I'm trying to update the schema of existing table using patch via ruby Google API Client.
Here's the code:
def updateTable(client, bq, schema,dataset,table)
result = client.execute(:api_method => bq.tables.patch,
:parameters => {'projectId' => PROJECT, 'datasetId' => dataset, 'tableId' => table},
:body_object => {
"tableReference" => {
"datasetId" => dataset,
"projectId" => "mydataset-1",
"tableId" => table
},
"schema" => schema
}
)
puts result.body
end
Here's the error I get:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalid",
"message": "Invalid schema update. Field a_b_testing_group is missing in new schema"
}
],
"code": 400,
"message": "Invalid schema update. Field a_b_testing_group is missing in new schema"
}
}
I'll appreciate any pointers, suggestions.
Thanks,
Here's a sample schema:
{ "fields" : [
{ "fields" : [
{ "mode" : "NULLABLE",
"name" : "time",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "attempts",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "mode",
"type" : "STRING"
},
{ "mode" : "NULLABLE",
"name" : "distinct_id",
"type" : "STRING"
},
{ "mode" : "NULLABLE",
"name" : "waited",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "party_size",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "version",
"type" : "STRING"
},
{ "mode" : "NULLABLE",
"name" : "region",
"type" : "STRING"
},
{ "mode" : "NULLABLE",
"name" : "reachability",
"type" : "STRING"
},
{ "mode" : "NULLABLE",
"name" : "device",
"type" : "STRING"
},
{ "mode" : "NULLABLE",
"name" : "_os",
"type" : "STRING"
},
{ "mode" : "NULLABLE",
"name" : "a_b_testing_group",
"type" : "STRING"
},
{ "mode" : "NULLABLE",
"name" : "item_name",
"type" : "STRING"
},
{ "mode" : "NULLABLE",
"name" : "price",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "contestant",
"type" : "STRING"
},
{ "mode" : "NULLABLE",
"name" : "mp_country_code",
"type" : "STRING"
},
{ "mode" : "NULLABLE",
"name" : "_city",
"type" : "STRING"
},
{ "mode" : "NULLABLE",
"name" : "_region",
"type" : "STRING"
},
{ "mode" : "NULLABLE",
"name" : "source",
"type" : "STRING"
},
{ "mode" : "NULLABLE",
"name" : "label",
"type" : "STRING"
},
{ "mode" : "NULLABLE",
"name" : "sku",
"type" : "STRING"
},
{ "mode" : "NULLABLE",
"name" : "balance__soft_",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "balance__hard_",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "price__soft_",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "free",
"type" : "BOOLEAN"
},
{ "mode" : "NULLABLE",
"name" : "price__hard_",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "magical_damage_dealt",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "magical_damage_dealt__players_",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "player_kills",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "damage_taken",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "duration",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "items_consumed",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "magical_damage_taken",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "physical_damage_dealt__players_",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "disconnects",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "items_sold",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "physical_damage_taken",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "healing_done",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "matches",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "relic",
"type" : "STRING"
},
{ "mode" : "NULLABLE",
"name" : "assists",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "largest_kill_streak",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "bots",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "gold",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "largest_multi_kill",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "ping",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "team",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "tribute_kills",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "connects",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "deaths",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "shrine_captures",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "spawns",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "items_bought",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "physical_damage_dealt",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "abandoned",
"type" : "BOOLEAN"
},
{ "mode" : "NULLABLE",
"name" : "damage_dealt",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "damage_dealt__players_",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "level",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "party_muted",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "quests_completed",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "tower_kills",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "victorious",
"type" : "BOOLEAN"
},
{ "mode" : "NULLABLE",
"name" : "name",
"type" : "STRING"
},
{ "mode" : "NULLABLE",
"name" : "response",
"type" : "STRING"
},
{ "mode" : "NULLABLE",
"name" : "type",
"type" : "STRING"
},
{ "mode" : "NULLABLE",
"name" : "currency_type",
"type" : "STRING"
},
{ "mode" : "NULLABLE",
"name" : "state",
"type" : "STRING"
},
{ "mode" : "NULLABLE",
"name" : "last_quest",
"type" : "STRING"
},
{ "mode" : "NULLABLE",
"name" : "product",
"type" : "STRING"
},
{ "mode" : "NULLABLE",
"name" : "amount",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "platform",
"type" : "STRING"
},
{ "mode" : "NULLABLE",
"name" : "newbie",
"type" : "BOOLEAN"
},
{ "mode" : "NULLABLE",
"name" : "campaign_id",
"type" : "FLOAT"
},
{ "mode" : "NULLABLE",
"name" : "delivery_id",
"type" : "FLOAT"
}
],
"mode" : "NULLABLE",
"name" : "properties",
"type" : "RECORD"
},
{ "mode" : "NULLABLE",
"name" : "event",
"type" : "STRING"
}
] }
BigQuery supports adding columns to existing tables, but not removing existing ones.
To prevent the error shown, when patching a table schema, always include existing columns in the new schema, and only add columns to it.

Trying to parse a Json with Open Refine GREL

I'm trying to parse this JSON but really can't find the way to extract the data I want.
{ "results" :
[ { "address_components" :
[
{ "long_name" : "44", "short_name" : "44", "types" : [ "street_number" ] },
{ "long_name" : "Rue Montaigne", "short_name" : "Rue Montaigne", "types" : [ "route" ] },
{ "long_name" : "Agen", "short_name" : "Agen", "types" : [ "locality", "political" ] },
{ "long_name" : "Lot-et-Garonne", "short_name" : "Lot-et-Garonne", "types" : [ "administrative_area_level_2", "political" ] },
{ "long_name" : "Aquitaine", "short_name" : "Aquitaine", "types" : [ "administrative_area_level_1", "political" ] },
{ "long_name" : "France", "short_name" : "FR", "types" : [ "country", "political" ] },
{ "long_name" : "47000", "short_name" : "47000", "types" : [ "postal_code" ] }
],
"formatted_address" : "44 Rue Montaigne, 47000 Agen, France",
"geometry" : {
"bounds" : {
"northeast" : { "lat" : 44.1994907, "lng" : 0.6172573 },
"southwest" : { "lat" : 44.19949039999999, "lng" : 0.6172388999999999 }
},
"location" : { "lat" : 44.19949039999999, "lng" : 0.6172573 },
"location_type" : "RANGE_INTERPOLATED",
"viewport" : {
"northeast" : { "lat" : 44.20083953029149, "lng" : 0.618597080291502 },
"southwest" : { "lat" : 44.1981415697085, "lng" : 0.6158991197084979 }
}
},
"partial_match" : true,
"types" : [ "street_address" ]
} ],
"status" : "OK" }
I'm trying to isolate the lat and the lng from the point I geolocalized with Google Refine GREL ("location" : { "lat" : 44.19949039999999, "lng" : 0.6172573 }).
Can you give me a hint of what I should do to succeed?
Try this:
with(value.parseJson().results[0].geometry.location, pair, pair.lat +", " + pair.lng)

Looking for a good and free reverse geocoding API [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
I am familiar with two reverse geocoding APIs - Google Maps and foursquare. Both have problems. Consider lat,lng = 35.699,139.707 (Tokyo).
Foursquare:
GET https://api.foursquare.com/v2/venues/search?ll=35.699,139.707&oauth_token=5TJR4WQZSOW0ZWTE4ENMXKO3Y415252GITEMRPQIVPMEGCYK&v=20120723&limit=1
yields the following result:
{
"meta": {
"code": 200
},
"notifications": [
{
"type": "notificationTray",
"item": {
"unreadCount": 0
}
}
],
"response": {
"venues": [
{
"id": "4b64ebedf964a520e3d92ae3",
"name": "まいどおおきに食堂 東新宿食堂",
"contact": {
"phone": "0352911870",
"formattedPhone": "03-5291-1870"
},
"location": {
"address": "大久保1-1-45",
"crossStreet": "新宿セントラルハイツプラザ 1F",
"lat": 35.698492646211,
"lng": 139.707271456718,
"distance": 61,
"postalCode": "169-0072",
"city": "新宿区",
"state": "東京都",
"country": "Japan",
"cc": "JP"
},
"categories": [
{
"id": "4bf58dd8d48988d111941735",
"name": "Restaurant japonais",
"pluralName": "Restaurants japonais",
"shortName": "Japonaise",
"icon": {
"prefix": "https://foursquare.com/img/categories_v2/food/japanese_",
"suffix": ".png"
},
"primary": true
}
],
"verified": false,
"stats": {
"checkinsCount": 191,
"usersCount": 100,
"tipCount": 1
},
"url": "http://www.shokudo.jp/",
"likes": {
"count": 0,
"groups": []
},
"specials": {
"count": 0,
"items": []
},
"hereNow": {
"count": 0,
"groups": []
}
}
]
}
}
I am only interested in the response.venues[0].location.city entry. Unfortunately, I do not know Japanese, so I cannot tell what it is. Well, google says it is Shinjuku - one of the special wards of Tokyo.
Google Maps:
GET http://maps.googleapis.com/maps/api/geocode/json?sensor=false&language=en&latlng=35.699,139.707
yields:
{
"results" : [
{
"address_components" : [
{
"long_name" : "41",
"short_name" : "41",
"types" : [ "sublocality_level_4", "sublocality", "political" ]
},
{
"long_name" : "1",
"short_name" : "1",
"types" : [ "sublocality_level_3", "sublocality", "political" ]
},
{
"long_name" : "1丁目",
"short_name" : "1丁目",
"types" : [ "sublocality_level_2", "sublocality", "political" ]
},
{
"long_name" : "Okubo",
"short_name" : "Okubo",
"types" : [ "sublocality_level_1", "sublocality", "political" ]
},
{
"long_name" : "Shinjuku",
"short_name" : "Shinjuku",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Tokyo",
"short_name" : "Tokyo",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Japan",
"short_name" : "JP",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Japan, Tokyo, Shinjuku, Okubo, 1丁目1−41",
"geometry" : {
"location" : {
"lat" : 35.69893960,
"lng" : 139.7069460
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 35.70028858029149,
"lng" : 139.7082949802915
},
"southwest" : {
"lat" : 35.69759061970850,
"lng" : 139.7055970197085
}
}
},
"types" : [ "sublocality_level_4", "sublocality", "political" ]
},
{
"address_components" : [
{
"long_name" : "169-8540",
"short_name" : "169-8540",
"types" : [ "postal_code" ]
},
{
"long_name" : "2",
"short_name" : "2",
"types" : [ "sublocality_level_3", "sublocality", "political" ]
},
{
"long_name" : "1丁目",
"short_name" : "1丁目",
"types" : [ "sublocality_level_2", "sublocality", "political" ]
},
{
"long_name" : "Okubo",
"short_name" : "Okubo",
"types" : [ "sublocality_level_1", "sublocality", "political" ]
},
{
"long_name" : "Shinjuku",
"short_name" : "Shinjuku",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Tokyo",
"short_name" : "Tokyo",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Japan",
"short_name" : "JP",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "1丁目-2 Okubo, Shinjuku, Tokyo 169-8540, Japan",
"geometry" : {
"location" : {
"lat" : 35.69946460,
"lng" : 139.70746810
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 35.70081358029149,
"lng" : 139.7088170802915
},
"southwest" : {
"lat" : 35.69811561970850,
"lng" : 139.7061191197085
}
}
},
"types" : [ "postal_code" ]
},
{
"address_components" : [
{
"long_name" : "1",
"short_name" : "1",
"types" : [ "sublocality_level_3", "sublocality", "political" ]
},
{
"long_name" : "1丁目",
"short_name" : "1丁目",
"types" : [ "sublocality_level_2", "sublocality", "political" ]
},
{
"long_name" : "Okubo",
"short_name" : "Okubo",
"types" : [ "sublocality_level_1", "sublocality", "political" ]
},
{
"long_name" : "Shinjuku",
"short_name" : "Shinjuku",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Tokyo",
"short_name" : "Tokyo",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Japan",
"short_name" : "JP",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Japan, Tokyo, Shinjuku, Okubo, 1丁目1",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 35.69984490,
"lng" : 139.70749510
},
"southwest" : {
"lat" : 35.69787060,
"lng" : 139.70506090
}
},
"location" : {
"lat" : 35.69880630,
"lng" : 139.70610160
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 35.70020673029150,
"lng" : 139.7076269802915
},
"southwest" : {
"lat" : 35.69750876970850,
"lng" : 139.7049290197085
}
}
},
"types" : [ "sublocality_level_3", "sublocality", "political" ]
},
{
"address_components" : [
{
"long_name" : "1丁目",
"short_name" : "1丁目",
"types" : [ "sublocality_level_2", "sublocality", "political" ]
},
{
"long_name" : "Okubo",
"short_name" : "Okubo",
"types" : [ "sublocality_level_1", "sublocality", "political" ]
},
{
"long_name" : "Shinjuku",
"short_name" : "Shinjuku",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Tokyo",
"short_name" : "Tokyo",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Japan",
"short_name" : "JP",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Japan, Tokyo, Shinjuku, Okubo, 1丁目",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 35.70128920,
"lng" : 139.70796940
},
"southwest" : {
"lat" : 35.69787060,
"lng" : 139.7019760
}
},
"location" : {
"lat" : 35.69868950,
"lng" : 139.70306310
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 35.70128920,
"lng" : 139.70796940
},
"southwest" : {
"lat" : 35.69787060,
"lng" : 139.7019760
}
}
},
"types" : [ "sublocality_level_2", "sublocality", "political" ]
},
{
"address_components" : [
{
"long_name" : "Okubo",
"short_name" : "Okubo",
"types" : [ "sublocality_level_1", "sublocality", "political" ]
},
{
"long_name" : "Shinjuku",
"short_name" : "Shinjuku",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Tokyo",
"short_name" : "Tokyo",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Japan",
"short_name" : "JP",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Okubo, Shinjuku, Tokyo, Japan",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 35.70956610,
"lng" : 139.7091340
},
"southwest" : {
"lat" : 35.69787310,
"lng" : 139.70060080
}
},
"location" : {
"lat" : 35.70418340,
"lng" : 139.70558750
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 35.70956610,
"lng" : 139.7091340
},
"southwest" : {
"lat" : 35.69787310,
"lng" : 139.70060080
}
}
},
"types" : [ "sublocality_level_1", "sublocality", "political" ]
},
{
"address_components" : [
{
"long_name" : "Higashishinjuku Station",
"short_name" : "Higashishinjuku Station",
"types" : [ "train_station", "transit_station", "establishment" ]
},
{
"long_name" : "27",
"short_name" : "27",
"types" : [ "sublocality_level_3", "sublocality", "political" ]
},
{
"long_name" : "7丁目",
"short_name" : "7丁目",
"types" : [ "sublocality_level_2", "sublocality", "political" ]
},
{
"long_name" : "Shinjuku",
"short_name" : "Shinjuku",
"types" : [ "sublocality_level_1", "sublocality", "political" ]
},
{
"long_name" : "Shinjuku",
"short_name" : "Shinjuku",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Tokyo",
"short_name" : "Tokyo",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Japan",
"short_name" : "JP",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Higashishinjuku Station, 7丁目-27 Shinjuku, Tokyo, Japan",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 35.7050830,
"lng" : 139.7144590
},
"southwest" : {
"lat" : 35.6926030,
"lng" : 139.7000410
}
},
"location" : {
"lat" : 35.697920,
"lng" : 139.7075490
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 35.7050830,
"lng" : 139.7144590
},
"southwest" : {
"lat" : 35.6926030,
"lng" : 139.7000410
}
}
},
"types" : [ "train_station", "transit_station", "establishment" ]
},
{
"address_components" : [
{
"long_name" : "169-0072",
"short_name" : "169-0072",
"types" : [ "postal_code" ]
},
{
"long_name" : "Okubo",
"short_name" : "Okubo",
"types" : [ "sublocality_level_1", "sublocality", "political" ]
},
{
"long_name" : "Shinjuku",
"short_name" : "Shinjuku",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Tokyo",
"short_name" : "Tokyo",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Japan",
"short_name" : "JP",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Okubo, Shinjuku, Tokyo 169-0072, Japan",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 35.70972520,
"lng" : 139.71028470
},
"southwest" : {
"lat" : 35.69710930,
"lng" : 139.69624280
}
},
"location" : {
"lat" : 35.70418340,
"lng" : 139.70558750
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 35.70972520,
"lng" : 139.71028470
},
"southwest" : {
"lat" : 35.69710930,
"lng" : 139.69624280
}
}
},
"types" : [ "postal_code" ]
},
{
"address_components" : [
{
"long_name" : "Shinokubo Station",
"short_name" : "Shinokubo Station",
"types" : [ "train_station", "transit_station", "establishment" ]
},
{
"long_name" : "10",
"short_name" : "10",
"types" : [ "sublocality_level_3", "sublocality", "political" ]
},
{
"long_name" : "1丁目",
"short_name" : "1丁目",
"types" : [ "sublocality_level_2", "sublocality", "political" ]
},
{
"long_name" : "Hyakunincho",
"short_name" : "Hyakunincho",
"types" : [ "sublocality_level_1", "sublocality", "political" ]
},
{
"long_name" : "Shinjuku",
"short_name" : "Shinjuku",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Tokyo",
"short_name" : "Tokyo",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Japan",
"short_name" : "JP",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Shinokubo Station, 1丁目-10 Hyakunincho, Shinjuku, Tokyo, Japan",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 35.7078270,
"lng" : 139.708840
},
"southwest" : {
"lat" : 35.6953970,
"lng" : 139.6937970
}
},
"location" : {
"lat" : 35.7013060,
"lng" : 139.7000440
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 35.7078270,
"lng" : 139.708840
},
"southwest" : {
"lat" : 35.6953970,
"lng" : 139.6937970
}
}
},
"types" : [ "train_station", "transit_station", "establishment" ]
},
{
"address_components" : [
{
"long_name" : "Shinjuku Station",
"short_name" : "Shinjuku Station",
"types" : [ "train_station", "transit_station", "establishment" ]
},
{
"long_name" : "38",
"short_name" : "38",
"types" : [ "sublocality_level_3", "sublocality", "political" ]
},
{
"long_name" : "3丁目",
"short_name" : "3丁目",
"types" : [ "sublocality_level_2", "sublocality", "political" ]
},
{
"long_name" : "Shinjuku",
"short_name" : "Shinjuku",
"types" : [ "sublocality_level_1", "sublocality", "political" ]
},
{
"long_name" : "Shinjuku",
"short_name" : "Shinjuku",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Tokyo",
"short_name" : "Tokyo",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Japan",
"short_name" : "JP",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Shinjuku Station, 3丁目-38 Shinjuku, Tokyo, Japan",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 35.7005790,
"lng" : 139.7124960
},
"southwest" : {
"lat" : 35.6812220,
"lng" : 139.6878250
}
},
"location" : {
"lat" : 35.6909210,
"lng" : 139.7002580
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 35.7005790,
"lng" : 139.7124960
},
"southwest" : {
"lat" : 35.6812220,
"lng" : 139.6878250
}
}
},
"types" : [ "train_station", "transit_station", "establishment" ]
},
{
"address_components" : [
{
"long_name" : "160-0022",
"short_name" : "160-0022",
"types" : [ "postal_code" ]
},
{
"long_name" : "Shinjuku",
"short_name" : "Shinjuku",
"types" : [ "sublocality_level_1", "sublocality", "political" ]
},
{
"long_name" : "Shinjuku",
"short_name" : "Shinjuku",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Tokyo",
"short_name" : "Tokyo",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Japan",
"short_name" : "JP",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Shinjuku, Tokyo 160-0022, Japan",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 35.70311470,
"lng" : 139.71922230
},
"southwest" : {
"lat" : 35.68222330,
"lng" : 139.69241360
}
},
"location" : {
"lat" : 35.69110170,
"lng" : 139.7067630
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 35.70311470,
"lng" : 139.71922230
},
"southwest" : {
"lat" : 35.68222330,
"lng" : 139.69241360
}
}
},
"types" : [ "postal_code" ]
},
/* REMOVED FOR BREVITY */
],
"status" : "OK"
}
Google Maps API is in English, but its results are too low level. For instance, cities and towns are normally identified with the locality type. Here the locality is Shinjuku, which is one of the special wards of Tokyo, but it is an implementation detail of the administration system of Tokyo. I want to get Tokyo as the city. Of course, I could search for the administrative_area_level_1 type token instead of the locality, knowing that Tokyo is actually one of the Japan prefectures.
The foursquare API has the same problem, it reports the city as Shinjuku and the state as Tokyo, only both as in Japanese!
Are there any simple high level reverse geocoding API which returns common sense results? I mean, no one outside Japan says "I am going to Shinjuku". People say "I am going to Tokyo".
Thanks.
OpenStreeMap has a reverse lookup tool too:
http://wiki.openstreetmap.org/wiki/Nominatim#Reverse_Geocoding_.2F_Address_lookup
Example from link:
Query:
http://nominatim.openstreetmap.org/reverse?format=xml&lat=52.5487429714954&lon=-1.81602098644987&zoom=18&addressdetails=1
Result:
<reversegeocode timestamp="Fri, 06 Nov 09 16:33:54 +0000" querystring="...">
<result place_id="1620612" osm_type="node" osm_id="452010817">
135, Pilkington Avenue, Wylde Green, City of Birmingham, West Midlands (county), B72, United Kingdom
</result>
<addressparts>
<house>135</house>
<road>Pilkington Avenue</road>
<village>Wylde Green</village>
<town>Sutton Coldfield</town>
<city>City of Birmingham</city>
<county>West Midlands (county)</county>
<postcode>B72</postcode>
<country>United Kingdom</country>
<country_code>gb</country_code>
</addressparts>
</reversegeocode>
The Yahoo Maps API may be able to help you out, because it offers the ability to set the precision.
Try GeocodeFarm.
250 free queries daily per IP based but the web service is free for unlimited and the cheap $25 gives you 25,000 queries daily (which is what I use for my apps).
Results are easy to understand, thorough documentation, forward and reverse, etc.
You can try Bing Maps I don't know how accurate it is, but you can try it
http://dev.virtualearth.net/services/v1/geocodeservice/geocodeservice.asmx/ReverseGeocode?latitude=[NUMBER]&longitude=[NUMBER]&key=[MAPS_KEY]&culture=%22en-us%22&format=json

My app crashes when trying to get a String containing special characters

when i try to display a String, my application crashes:
NSLog(#"The start point is: %#",startPt);
This is the startPt value: 39-49%20Avenue%20d'Ivry,%2075013%20Paris,%20France. Actually it's returned from the Google Maps web service.
Sometimes, the application didn't crashes, but i got something weird in the Log:
The start point is: text/javascript
Why i am not able to assign the String 39-49%20Avenue%20d'Ivry,%2075013%20Paris,%20France to a NSString variable?
EDIT:
Here is the JSON response parsing:
NSString *responseString=[request responseString];
NSDictionary *responseDict=[responseString JSONValue];
NSArray *resultsArray = [responseDict objectForKey:#"results"];
location=[[resultsArray valueForKey:#"formatted_address"] objectAtIndex:0];
location=[location stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSLog(#"The location is : %#",location);//39-49%20Avenue%20d'Ivry,%2075013%20Paris,%20France
And this is the JSON response returned from the Google maps API:
{
"results" : [
{
"address_components" : [
{
"long_name" : "39-49",
"short_name" : "39-49",
"types" : [ "street_number" ]
},
{
"long_name" : "Avenue d'Ivry",
"short_name" : "Avenue d'Ivry",
"types" : [ "route" ]
},
{
"long_name" : "Quartier de la Gare",
"short_name" : "Quartier de la Gare",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "13th arrondissement of Paris",
"short_name" : "13th arrondissement of Paris",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Paris",
"short_name" : "Paris",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Paris",
"short_name" : "75",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Île-de-France",
"short_name" : "IdF",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "France",
"short_name" : "FR",
"types" : [ "country", "political" ]
},
{
"long_name" : "75013",
"short_name" : "75013",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "39-49 Avenue d'Ivry, 75013 Paris, France",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 48.82332110,
"lng" : 2.36638740
},
"southwest" : {
"lat" : 48.82296810,
"lng" : 2.36571090
}
},
"location" : {
"lat" : 48.82313960,
"lng" : 2.36602210
},
"location_type" : "RANGE_INTERPOLATED",
"viewport" : {
"northeast" : {
"lat" : 48.82449358029150,
"lng" : 2.367398130291502
},
"southwest" : {
"lat" : 48.82179561970850,
"lng" : 2.364700169708498
}
}
},
"types" : [ "street_address" ]
},
{
"address_components" : [
{
"long_name" : "Quartier de la Gare",
"short_name" : "Quartier de la Gare",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "13th arrondissement of Paris",
"short_name" : "13th arrondissement of Paris",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Paris",
"short_name" : "Paris",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Paris",
"short_name" : "75",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Île-de-France",
"short_name" : "IdF",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "France",
"short_name" : "FR",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Quartier de la Gare, Paris, France",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 48.83810700000001,
"lng" : 2.3869610
},
"southwest" : {
"lat" : 48.8189240,
"lng" : 2.3556050
}
},
"location" : {
"lat" : 48.82807520,
"lng" : 2.36740680
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 48.83810700000001,
"lng" : 2.3869610
},
"southwest" : {
"lat" : 48.8189240,
"lng" : 2.3556050
}
}
},
"types" : [ "neighborhood", "political" ]
},
{
"address_components" : [
{
"long_name" : "13th arrondissement of Paris",
"short_name" : "13th arrondissement of Paris",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Paris",
"short_name" : "Paris",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Paris",
"short_name" : "75",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Île-de-France",
"short_name" : "IdF",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "France",
"short_name" : "FR",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "13th arrondissement of Paris, Paris, France",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 48.84496499999999,
"lng" : 2.3900530
},
"southwest" : {
"lat" : 48.8155730,
"lng" : 2.3411080
}
},
"location" : {
"lat" : 48.83222220,
"lng" : 2.35555560
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 48.84496499999999,
"lng" : 2.3900530
},
"southwest" : {
"lat" : 48.8155730,
"lng" : 2.3411080
}
}
},
"types" : [ "sublocality", "political" ]
},
{
"address_components" : [
{
"long_name" : "75013",
"short_name" : "75013",
"types" : [ "postal_code" ]
},
{
"long_name" : "Paris",
"short_name" : "Paris",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Paris",
"short_name" : "75",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Île-de-France",
"short_name" : "IdF",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "France",
"short_name" : "FR",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "75013 Paris, France",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 48.84493089999999,
"lng" : 2.39026440
},
"southwest" : {
"lat" : 48.81587960,
"lng" : 2.34112720
}
},
"location" : {
"lat" : 48.8307590,
"lng" : 2.3592040
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 48.84493089999999,
"lng" : 2.39026440
},
"southwest" : {
"lat" : 48.81587960,
"lng" : 2.34112720
}
}
},
"types" : [ "postal_code" ]
},
{
"address_components" : [
{
"long_name" : "Paris",
"short_name" : "Paris",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Paris",
"short_name" : "75",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Île-de-France",
"short_name" : "IdF",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "France",
"short_name" : "FR",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Paris, France",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 48.9021450,
"lng" : 2.46992090
},
"southwest" : {
"lat" : 48.8155730,
"lng" : 2.2241990
}
},
"location" : {
"lat" : 48.8566140,
"lng" : 2.35222190
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 48.9021450,
"lng" : 2.46992090
},
"southwest" : {
"lat" : 48.8155730,
"lng" : 2.2241990
}
}
},
"types" : [ "locality", "political" ]
},
{
"address_components" : [
{
"long_name" : "Paris",
"short_name" : "75",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Île-de-France",
"short_name" : "IdF",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "France",
"short_name" : "FR",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Paris, France",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 48.9021450,
"lng" : 2.46992090
},
"southwest" : {
"lat" : 48.8155730,
"lng" : 2.2241990
}
},
"location" : {
"lat" : 48.87633370,
"lng" : 2.34612070
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 48.9021450,
"lng" : 2.46992090
},
"southwest" : {
"lat" : 48.8155730,
"lng" : 2.2241990
}
}
},
"types" : [ "administrative_area_level_2", "political" ]
},
{
"address_components" : [
{
"long_name" : "Île-de-France",
"short_name" : "IdF",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "France",
"short_name" : "FR",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Île-de-France, France",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 49.2415040,
"lng" : 3.5590070
},
"southwest" : {
"lat" : 48.1200810,
"lng" : 1.446170
}
},
"location" : {
"lat" : 48.84991980,
"lng" : 2.63704110
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 49.2415040,
"lng" : 3.5590070
},
"southwest" : {
"lat" : 48.1200810,
"lng" : 1.446170
}
}
},
"types" : [ "administrative_area_level_1", "political" ]
},
{
"address_components" : [
{
"long_name" : "France",
"short_name" : "FR",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "France",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 51.08896180,
"lng" : 9.559956999999999
},
"southwest" : {
"lat" : 41.34232760,
"lng" : -5.1412280
}
},
"location" : {
"lat" : 46.2276380,
"lng" : 2.2137490
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 51.08896180,
"lng" : 9.559956999999999
},
"southwest" : {
"lat" : 41.34232760,
"lng" : -5.1412280
}
}
},
"types" : [ "country", "political" ]
}
],
"status" : "OK"
}
I can think of two possibilities :
(1) Why do you assume the string is ASCII? Try a different encoding :
location = [location stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
Perhaps Google are using a unicode ' instead of one within the ASCII set? And if you're looking at address data then you can be fairly sure that odd characters are going to get put in there!
and (2) (this one is more unlikely given you have posted the JSON in your question but worth thinking about)
When you first get location you aren't checking that it's actually a string (you aren't checking that 'formatted_address' is an array either!)
What if the JSON returned was this (say there is a bug in the server?) :
{
...
"formatted_address" : [ { } ]
...
}
Here, [[resultsArray valueForKey:#"formatted_address"] objectAtIndex:0]; would work, but it wouldn't return an NSString.
Try adding in this kind of check :
location=[[resultsArray valueForKey:#"formatted_address"] objectAtIndex:0];
if (NO == [location isKindOfClass:[NSString class]]) {
NSLog(#"Location wasn't a string (%#) : %#", [location class], location);
} else {
location=[location stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSLog(#"The location is : %#",location);//39-49%20Avenue%20d'Ivry,%2075013%20Paris,%20France
}
My guess is that startPt isn't an NSString, but rather a char*. If that's the case, the simplest way to create an NSString from it is with [NSString stringWithFormat:#"%s", startPt].