Firebase - Download specific child (Swift 3) - ios

I have attached a picture of my JSON tree
{
"-Ko4cg3ik5OFsnLTI4q4" : {
"FacebookPage" : {
"id" : "187736205061418",
"page" : "partyunlimitedtoronto"
},
"MapView" : {
"Edate" : 523940400,
"Sdate" : 523929600,
"intersted" : 3843,
"lat" : 45.510772273476,
"lng" : -73.563586483671,
"type" : "MUSIC",
"userID" : 1373802105986614,
"visibility" : "Public"
},
"address" : "Théâtre Corona",
"bio" : "evenko & Greenland Productions présentent\t\nMogwai\navec/with Xander Harris \nPortes: 19h00 - Spectacle: 20h00\n\nMise en vente: 24 mars à 10h\n\n37$ à 42$\n\nPrix lors de l’achat à la billetterie / Des frais de manutention peuvent s’appliquer lors de l’achat en ligne.\n\n.....................................................\n\nDoors: 7:00 pm - Show: 8:00 pm\n\nOn Sale: March 24 at 10am\n\n$37 to $42\n\nPrices for box office purchase / Handling fees may apply for online purchase.",
"name" : "Mogwai // Montréal",
"pic" : "https://scontent.xx.fbcdn.net/v/t1.0-9/17361785_10155183713782422_6829705267219994059_n.jpg?oh=150f6f53c74233b70b7f1b372c1db1e4&oe=59CF07EE",
"site" : "http://www.evenko.ca/fr/evenements/12392/mogwai/theatre-corona/12-06-2017",
"status" : "normal"
},
"-Ko4cgP2rXJCIRBODWpm" : {
"FacebookPage" : {
"id" : "620998508097068",
"page" : "partyunlimitedtoronto"
},
"MapView" : {
"Edate" : 43223454,
"Sdate" : 65837495,
"interested" : 2355,
"lat" : 45.3846583,
"lng" : -74.4736583,
"type" : "Party",
"userID" : 1373802105986614,
"visibility " : "Public"
},
"address" : "Théâtre Corona",
"bio" : "Greenland Productions & evenko présentent\t\t\t\t\t\t\nNazareth\t\t\t\navec/with Les Deuxluxes\t\n\nPortes: 19h00 - Spectacle: 20h00\n\nMise en vente: 14 avril à midi \n\n44,50$ à 48$\n\nPrix lors de l’achat à la billetterie / Des frais de manutention peuvent s’appliquer lors de l’achat en ligne.\n\n.....................................................\n\nDoors: 7:00 pm - Show: 8:00 pm\n\nOn Sale: April 14 at noon\n\n$44,50 to $48\n\nPrices for box office purchase / Handling fees may apply for online purchase.",
"name" : "Nazareth // Montréal",
"pic" : "https://scontent.xx.fbcdn.net/v/t1.0-9/17759677_10155255160737422_1735715699829358715_n.jpg?oh=1d6d1c250c2c6b38c6ef0de4483bd0a9&oe=5A0C4879",
"site" : "http://www.evenko.ca/fr/evenements/12489/nazareth/theatre-corona/08-03-2017",
"status" : "normal"
}
}
So I'm attempting to only download the "MapView" node inside every child when I run my program but in this case, I won't know the name of the parent of "MapView". Is there any way to only download a specific child like in this case. Otherwise, I was thinking whether I should use this style of structuring.
{
"EventView" : {
"-Ko4cg3ik5OFsnLTI4q4" : {
"FacebookPage" : {
"id" : "187736205061418",
"page" : "partyunlimitedtoronto"
},
"address" : "Théâtre Corona",
"bio" : "evenko & Greenland Productions présentent\t\nMogwai\navec/with Xander Harris \nPortes: 19h00 - Spectacle: 20h00\n\nMise en vente: 24 mars à 10h\n\n37$ à 42$\n\nPrix lors de l’achat à la billetterie / Des frais de manutention peuvent s’appliquer lors de l’achat en ligne.\n\n.....................................................\n\nDoors: 7:00 pm - Show: 8:00 pm\n\nOn Sale: March 24 at 10am\n\n$37 to $42\n\nPrices for box office purchase / Handling fees may apply for online purchase.",
"name" : "Mogwai // Montréal",
"pic" : "https://scontent.xx.fbcdn.net/v/t1.0-9/17361785_10155183713782422_6829705267219994059_n.jpg?oh=150f6f53c74233b70b7f1b372c1db1e4&oe=59CF07EE",
"site" : "http://www.evenko.ca/fr/evenements/12392/mogwai/theatre-corona/12-06-2017",
"status" : "normal"
},
"-Ko4cgP2rXJCIRBODWpm" : {
"FacebookPage" : {
"id" : "620998508097068",
"page" : "partyunlimitedtoronto"
},
"address" : "Théâtre Corona",
"bio" : "Greenland Productions & evenko présentent\t\t\t\t\t\t\nNazareth\t\t\t\navec/with Les Deuxluxes\t\n\nPortes: 19h00 - Spectacle: 20h00\n\nMise en vente: 14 avril à midi \n\n44,50$ à 48$\n\nPrix lors de l’achat à la billetterie / Des frais de manutention peuvent s’appliquer lors de l’achat en ligne.\n\n.....................................................\n\nDoors: 7:00 pm - Show: 8:00 pm\n\nOn Sale: April 14 at noon\n\n$44,50 to $48\n\nPrices for box office purchase / Handling fees may apply for online purchase.",
"name" : "Nazareth // Montréal",
"pic" : "https://scontent.xx.fbcdn.net/v/t1.0-9/17759677_10155255160737422_1735715699829358715_n.jpg?oh=1d6d1c250c2c6b38c6ef0de4483bd0a9&oe=5A0C4879",
"site" : "http://www.evenko.ca/fr/evenements/12489/nazareth/theatre-corona/08-03-2017",
"status" : "normal"
}
},
"MapView" : {
"-Ko4cg3ik5OFsnLTI4q4" : {
"Edate" : 534312000,
"Sdate" : 534301200,
"intersted" : 652,
"lat" : 45.4827983,
"lng" : -73.575107687761,
"type" : "MUSIC",
"userID" : "1373802105986614",
"visibility" : "Public"
},
"-Ko4cgP2rXJCIRBODWpm" : {
"Edate" : 523508400,
"Sdate" : 523497600,
"intersted" : 382,
"lat" : 45.4827983,
"lng" : -73.575107687761,
"type" : "MUSIC",
"userID" : "1373802105986614",
"visibility" : "Public"
}
}
}
where in this case I would have the information in a separate child but where there are parent nodes with the same name in both EventView and MapView.

For the First structure
This structure will definitely make our query download the whole EventView node
var AllMapViews = []; //<-- array of all mapview objects
var path = "/EventView";
firebase.database().ref(path)
.once("value")
.then(eventViews => {
eventViews.forEach(thisevent => {
AllMapViews.push(thisevent.val().MapView);
})
});
Hence the result of the above will look like this
AllMapViews = [
{ "EventDate":343,"Sdate" : 65837495 ..},
{ "EventDate":343,"Sdate" : 65837495 ..},
{ "EventDate":343,"Sdate" : 65837495 ..},
...
]
For the Second structure (My Choice)
This structure will allow our query download only MapViews for all EventViews. Hence, making it the structure of choice in your implementation. Though it will need you to monitor the main EventView nodes often to know when the main event is deleted so that you can also delete it's corresponding MapView.
var AllMapViews = []; //<-- array of all mapview objects
var path = "/MapViews";
firebase.database().ref(path)
.once("value")
.then(mapViews => {
mapViews.forEach(map => {
AllMapViews.push(map.val());
})
});
Hence the result of the above will look like this
AllMapViews = [
{ "EventDate":343,"Sdate" : 65837495 ..},
{ "EventDate":343,"Sdate" : 65837495 ..},
{ "EventDate":343,"Sdate" : 65837495 ..},
...
]

Related

Does POST /reviews-v1 using Crucible REST API allow us to add reviewers?

Is there a way to add reviewers when creating a code review through the REST API? I tried adding "reviewers" with an array of usernames but that didn't work. Got an error
Unrecognized field "reviewers" (Class com.atlassian.crucible.spi.data.ReviewData), not marked as ignorable
The request body example on their api docs is below:
{
"reviewData" : {
"projectKey" : "CR-FOO",
"name" : "Example review.",
"description" : "Description or statement of objectives for this example review.",
"author" : {
"userName" : "auth",
"displayName" : "Jane Authy",
},
"moderator" : {
"userName" : "scott",
"displayName" : "Scott the Moderator",
},
"creator" : {
"userName" : "joe",
"displayName" : "Joe Krustofski",
},
"permaId" : {
"id" : "CR-FOO-21"
},
"summary" : "some review summary.",
"state" : "Review",
"type" : "REVIEW",
"allowReviewersToJoin" : true,
"metricsVersion" : 4,
"createDate" : "2022-06-20T09:37:11.621+0000",
"dueDate" : "2022-06-23T09:37:11.621+0000",
"reminderDate" : "2022-06-21T09:37:11.621+0000",
"linkedIssues" : [ "DEF-456", "ABC-123", "GHI-789" ],
"jiraIssueKey" : "ABC-123"
},
"patch" : "Index: emptytests/notempty/a.txt\n===================================================================\ndiff -u -N -r1.31 -r1.32\n--- emptytests/notempty/a.txt\t22 Sep 2004 00:38:15 -0000\t1.31\n+++ emptytests/notempty/a.txt\t5 Dec 2004 01:04:25 -0000\t1.32\n## -4,4 +4,5 ##\n hello there :D\n CRU-123\n http://madbean.com/blog/\n-!\n\\ No newline at end of file\n+!\n+foobie\n\\ No newline at end of file\nIndex: test/a.txt\n===================================================================\ndiff -u -N -r1.31 -r1.32\n--- test/a.txt\t22 Sep 2004 00:38:15 -0000\t1.31\n+++ test/a.txt\t5 Dec 2004 01:04:25 -0000\t1.32\n## -4,4 +4,5 ##\n hello there :D\n CRU-123\n http://madbean.com/blog/\n-!\n\\ No newline at end of file\n+!\n+foobie\n\\ No newline at end of file",
"anchor" : {
"anchorPath" : "/",
"anchorRepository" : "REPO",
"stripCount" : 2
},
"changesets" : {
"changesetData" : [ {
"id" : "63452"
} ],
"repository" : "REPO"
}
}

mongodb shell to java driver aggregate statement

I'm able to run an aggregate MongoDb (3.8) request in the mongo shell but I can't get it out working using the java driver (3.4 java 8).
here's the input source structure. I want to aggregate informations to provide company activities stats. note that the ape document states for the company registered activity. I want to group on the first 3 digits of the ape code
{
"_id" : "00552017600016",
"sirene" : "005520176",
"nic" : "00016",
"natureCode" : "5710",
"natureLabel" : "SAS, société par actions simplifiée",
"name" : "HERNAS CARTONNAGE",
"brand" : "",
"registerDate" : ISODate("1954-12-31T23:00:00Z"),
"startDate" : ISODate("1954-12-31T23:00:00Z"),
"headquaters" : true,
"address" : {
"number" : 50,
"ext" : null,
"lane" : "RUE PASTEUR",
"zipcode" : "80210",
"city" : "FEUQUIERES EN VIMEU",
"country" : "FRANCE",
"location" : {
"type" : "Point",
"coordinates" : [
1.60319694244078,
50.0537636973407
],
"accuracy" : 0,
"ban" : "ADRNIVX_0000000260779642"
}
},
"ape" : {
"code" : "1721A",
"label" : "Fabrication de carton ondulé"
},
"staff" : {
"count" : 50,
"year" : 2016
}
}
running this commands in the shell works like a charm
db.companies_geo.aggregate([ {$match:{"address.city":"LE MANS"}},
{$group:{_id:{$substrBytes:["$ape.code",0,2]}, count:{$sum:1}, code:{$last:"$ape.code"}, label:{$last:"$ape.label"}}},
{$project:{count:1, code:1, label:1}},
{$sort:{count:-1}},
{$limit:20}
])
it produces this result
{ "_id" : "68", "count" : 4603, "code" : "6832B", "label" : "Supports juridiques de gestion de patrimoine immobilier" }
{ "_id" : "47", "count" : 1929, "code" : "4799B", "label" : "Vente par automate, aut. com. dét. hors mag., éventaire ou marché" }
{ "_id" : "94", "count" : 1874, "code" : "9499Z", "label" : "Autres organisations fonctionnant par adhésion volontaire" }
{ "_id" : "86", "count" : 1704, "code" : "8690F", "label" : "Activités de santé humaine non classées ailleurs" }
{ "_id" : "56", "count" : 832, "code" : "5630Z", "label" : "Débits de boissons" }
{ "_id" : "90", "count" : 816, "code" : "9004Z", "label" : "Gestion de salles de spectacles" }
{ "_id" : "85", "count" : 769, "code" : "8560Z", "label" : "Activités de soutien à l'enseignement" }
{ "_id" : "70", "count" : 592, "code" : "7022Z", "label" : "Conseil pour les affaires et autres conseils de gestion" }
{ "_id" : "96", "count" : 585, "code" : "9609Z", "label" : "Autres services personnels n.c.a." }
{ "_id" : "81", "count" : 582, "code" : "8130Z", "label" : "Services d'aménagement paysager" }
on the java side I've tried this but the code line bellow the while iteration raises the exception org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class com.mongodb.client.model.BsonField.
private List<Document> cityActivityGraph() {
Bson filter = Filters.eq("address.city", "LE MANS");
BsonField id = new BsonField("_id", Filters.eq(new Document("$substrBytes", Arrays.asList("$ape.code", 0, 2))));
BsonField count = Accumulators.sum("count", 1);
BsonField label = Accumulators.last("ape.label", 1);
BsonField code = Accumulators.last("ape.code", 1);
Bson group = Aggregates.group(id, count, code, label);
Bson match = Aggregates.match(filter);
Bson projections = Projections.include("code", "label", "count");
Bson project = Aggregates.project(projections);
Bson sort = Sorts.descending("count");
MongoCursor<Document> cursor = getTable().aggregate(Arrays.asList(
Aggregates.match(match),
Aggregates.group(group),
Aggregates.project(project),
Aggregates.sort(sort))).iterator(); <--- exception here
List<Document> result = new ArrayList<>();
while (cursor.hasNext()) {
Document doc = cursor.next();
System.out.println(doc.toJson());
result.add(doc);
}
return result;
}
any idea ? thanks in advance
found a solution, perhaps not the most efficient but it works
Bson id = new Document("_id", new Document("$substrBytes", Arrays.asList("$ape.code", 0, 3)));
BsonField code = Accumulators.last("code", "$ape.code");
BsonField label = Accumulators.last("label", "$ape.label");
BsonField count = Accumulators.sum("count", 1);
Bson projections = Projections.include("code", "label", "count");
Bson sort = Sorts.descending("count");
AggregateIterable<Document> stats = getTable().aggregate(Arrays.asList(
Aggregates.match(filter),
Aggregates.group(id, code, label, count),
Aggregates.project(projections),
Aggregates.limit(limit),
Aggregates.sort(sort)
));
List<Document> result = new ArrayList<>();
for (Document d:stats) {
result.add(d);
}
return result;

How to get values from this JSON using Alamofire swift 3

I'm trying to get values from this JSON. This is part of the JSON because the real JSON data is too long.
"hits" : [ {
"recipe" : {
"uri" : "http://www.edamam.com/ontologies/edamam.owl#recipe_bd8def1d09d8c308f659e6945f366271",
"label" : "Pinchos de carne",
"image" : "http://img.recetascomidas.com/recetas/640_480/pinchos-de-carne.jpg",
"source" : "Recetal Comidas",
"url" : "http://pinchos-de-carne.recetascomidas.com/",
"shareAs" : "http://www.edamam.com/recipe/pinchos-de-carne-bd8def1d09d8c308f659e6945f366271/carne",
"yield" : 6.0,
"dietLabels" : [ "Low-Carb" ],
"healthLabels" : [ "Dairy-Free", "Gluten-Free", "Egg-Free", "Peanut-Free", "Tree-Nut-Free", "Soy-Free", "Fish-Free", "Shellfish-Free" ],
"cautions" : [ ],
"ingredientLines" : [ "600 gr. de carne magra de cerdo", "2 cucharadas de pimentón dulce", "1 cucharada de pimentón picante", "1 cucharada de cúrcuma", "1 cucharada de sazonador especial para carnes", "3 cucharadas de perejil fresco bien picadito", "1/2 cucharada de comino", "Aceite de oliva", "3 patatas", "1 diente de ajo", "Pimienta negra", "Sal" ],
"ingredients" : [ {
"text" : "600 gr. de carne magra de cerdo",
"quantity" : 600.0,
"measure" : null,
"food" : "carne magra cerdo",
"weight" : 600.0
}, {
"text" : "2 cucharadas de pimentón dulce",
"quantity" : 2.0,
"measure" : "tbsp",
"food" : "pimenton dulce",
"weight" : 13.6
}, {
"text" : "1 cucharada de pimentón picante",
"quantity" : 1.0,
"measure" : "tbsp",
"food" : "pimenton picante",
"weight" : 6.8
}, {
"text" : "1 cucharada de cúrcuma",
"quantity" : 1.0,
"measure" : "tbsp",
"food" : "curcuma",
"weight" : 6.8
}, {
"text" : "1 cucharada de sazonador especial para carnes",
"quantity" : 1.0,
"measure" : "tbsp",
"food" : "sazonador",
"weight" : 2.7
}, {
"text" : "3 cucharadas de perejil fresco bien picadito",
"quantity" : 3.0,
"measure" : "tbsp",
"food" : "perejil fresco",
"weight" : 11.4
}, {
"text" : "1/2 cucharada de comino",
"quantity" : 0.5,
"measure" : "tbsp",
"food" : "comino",
"weight" : 3.0
}, {
"text" : "Aceite de oliva",
"quantity" : 2.0,
"measure" : "tbsp",
"food" : "aceite oliva",
"weight" : 27.0
}, {
"text" : "3 patatas",
"quantity" : 3.0,
"measure" : null,
"food" : "patatas",
"weight" : 195.0
}, {
"text" : "1 diente de ajo",
"quantity" : 1.0,
"measure" : null,
"food" : "ajo",
"weight" : 3.0
}, {
"text" : "Pimienta negra",
"quantity" : 1.0,
"measure" : "peppercorn",
"food" : "pimienta negra",
"weight" : 0.3
}, {
"text" : "Sal",
"quantity" : 0.0,
"measure" : null,
"food" : "sal",
"weight" : 3.3346887
} ]
For example, I want to get label values that is inside "recipe". I successfully print in console all the JSON, but I don't know how to get recipe values.
I hope you can help me.
This is the code I have now.
let url: String = "https://test-es.edamam.com/search?q=pollo"
var arregloHits: NSMutableArray = []
override func viewDidLoad() {
super.viewDidLoad()
pruebaJson()
}
func pruebaJson(){
if ControladorService.conexionInternet(){
ControladorService.sharedInstance.callUrlWithCompletion(url: url, params: nil, completion: { (finished, response) in
if finished{
let result = NSMutableArray(array: response["hits"] as! NSArray)
self.arregloHits = result
print(self.arregloHits)
}else{
print("Connection failed")
}
}, method: .get)
}else{
print("No Internet")
}
}
Your top level json structure is a dictionary. So you need to parse it into [String: Any]. Then your hints level is a JSON array, so you need to parse it into [Any]
Here is an example. Don't forget to handle unwrap
do{
let json = try JSONSerialization.jsonObject(with: yourJSONData, options: []) as? [String: Any]
let hits = json?["hits"] as? [Any]
dump(hits)
}catch let error{
}

How to get country name from currency code?

How to get country name from currency code? Is this possible or not?
Alternative option, using Swift 3 Locale class data:
struct CurrencyToRegionMapper {
static let locales = Locale.availableIdentifiers.map(Locale.init)
static func locales(currencyCode: String) -> Set<Locale> {
let localesWithCode = self.locales.filter { locale in
locale.currencyCode == currencyCode
}
return Set(localesWithCode)
}
static func locales(currencySymbol: String) -> Set<Locale> {
let localesWithSymbol = self.locales.filter { locale in
locale.currencySymbol == currencySymbol
}
return Set(localesWithSymbol)
}
static func regionNames(currencyCode: String, forLocale locale: Locale = Locale.autoupdatingCurrent) -> Set<String> {
let locale = Locale(identifier: locale.identifier) // .current and .autoupdatingCurrent doesn't work without this hack for some reason
let localesForCode = self.locales(currencyCode: currencyCode)
let names: [String] = localesForCode.flatMap { loc in
if let regionCode = loc.regionCode {
return locale.localizedString(forRegionCode: regionCode)
} else {
return locale.localizedString(forIdentifier: loc.identifier)
}
}
return Set(names)
}
static func regionNames(currencySymbol: String, forLocale locale: Locale = Locale.autoupdatingCurrent) -> Set<String> {
let locale = Locale(identifier: locale.identifier) // .current and .autoupdatingCurrent doesn't work without this hack for some reason
let localesForSymbol = self.locales(currencySymbol: currencySymbol)
let names: [String] = localesForSymbol.flatMap { loc in
if let regionCode = loc.regionCode {
return locale.localizedString(forRegionCode: regionCode)
} else {
return locale.localizedString(forIdentifier: loc.identifier)
}
}
return Set(names)
}
}
Usage:
CurrencyToRegionMapper.locales(currencyCode: "EUR") // Returns set of locales, where currency is Euro
CurrencyToRegionMapper.locales(currencySymbol: "$") // Returns set of locales, where currency symbol is $
CurrencyToRegionMapper.regionNames(currencyCode: "GBP", forLocale: Locale(identifier: "en_POSIX")) // Returns set of regions(countries) names which use british pound in POSIX locale: ["United Kingdom", "Guernsey", "Jersey", "Isle of Man"]
CurrencyToRegionMapper.regionNames(currencySymbol: "¥", forLocale: Locale(identifier: "fi_FI")) // Returns set of regions which use currency with symbol ¥ in Finnish locale: ["Kiina", "Japani"]
I found the whole list of currency codes and countires at this link
let codeToCountry = [
"AED" : "United Arab Emirates",
"AFN" : "Afghanistan",
"ALL" : "Albania",
"AMD" : "Armenia",
"ANG" : "Netherlands Antilles",
"AOA" : "Angola",
"ARS" : "Argentina",
"AUD" : "Australia, Australian Antarctic Territory, Christmas Island, Cocos (Keeling) Islands, Heard and McDonald Islands, Kiribati, Nauru, Norfolk Island, Tuvalu",
"AWG" : "Aruba",
"AZN" : "Azerbaijan",
"BAM" : "Bosnia and Herzegovina",
"BBD" : "Barbados",
"BDT" : "Bangladesh",
"BGN" : "Bulgaria",
"BHD" : "Bahrain",
"BIF" : "Burundi",
"BMD" : "Bermuda",
"BND" : "Brunei",
"BOB" : "Bolivia",
"BOV" : "Bolivia",
"BRL" : "Brazil",
"BSD" : "Bahamas",
"BTN" : "Bhutan",
"BWP" : "Botswana",
"BYR" : "Belarus",
"BZD" : "Belize",
"CAD" : "Canada",
"CDF" : "Democratic Republic of Congo",
"CHE" : "Switzerland",
"CHF" : "Switzerland, Liechtenstein",
"CHW" : "Switzerland",
"CLF" : "Chile",
"CLP" : "Chile",
"CNY" : "Mainland China",
"COP" : "Colombia",
"COU" : "Colombia",
"CRC" : "Costa Rica",
"CUP" : "Cuba",
"CVE" : "Cape Verde",
"CYP" : "Cyprus",
"CZK" : "Czech Republic",
"DJF" : "Djibouti",
"DKK" : "Denmark, Faroe Islands, Greenland",
"DOP" : "Dominican Republic",
"DZD" : "Algeria",
"EEK" : "Estonia",
"EGP" : "Egypt",
"ERN" : "Eritrea",
"ETB" : "Ethiopia",
"EUR" : "European Union, see eurozone",
"FJD" : "Fiji",
"FKP" : "Falkland Islands",
"GBP" : "United Kingdom",
"GEL" : "Georgia",
"GHS" : "Ghana",
"GIP" : "Gibraltar",
"GMD" : "Gambia",
"GNF" : "Guinea",
"GTQ" : "Guatemala",
"GYD" : "Guyana",
"HKD" : "Hong Kong Special Administrative Region",
"HNL" : "Honduras",
"HRK" : "Croatia",
"HTG" : "Haiti",
"HUF" : "Hungary",
"IDR" : "Indonesia",
"ILS" : "Israel",
"INR" : "Bhutan, India",
"IQD" : "Iraq",
"IRR" : "Iran",
"ISK" : "Iceland",
"JMD" : "Jamaica",
"JOD" : "Jordan",
"JPY" : "Japan",
"KES" : "Kenya",
"KGS" : "Kyrgyzstan",
"KHR" : "Cambodia",
"KMF" : "Comoros",
"KPW" : "North Korea",
"KRW" : "South Korea",
"KWD" : "Kuwait",
"KYD" : "Cayman Islands",
"KZT" : "Kazakhstan",
"LAK" : "Laos",
"LBP" : "Lebanon",
"LKR" : "Sri Lanka",
"LRD" : "Liberia",
"LSL" : "Lesotho",
"LTL" : "Lithuania",
"LVL" : "Latvia",
"LYD" : "Libya",
"MAD" : "Morocco, Western Sahara",
"MDL" : "Moldova",
"MGA" : "Madagascar",
"MKD" : "Former Yugoslav Republic of Macedonia",
"MMK" : "Myanmar",
"MNT" : "Mongolia",
"MOP" : "Macau Special Administrative Region",
"MRO" : "Mauritania",
"MTL" : "Malta",
"MUR" : "Mauritius",
"MVR" : "Maldives",
"MWK" : "Malawi",
"MXN" : "Mexico",
"MXV" : "Mexico",
"MYR" : "Malaysia",
"MZN" : "Mozambique",
"NAD" : "Namibia",
"NGN" : "Nigeria",
"NIO" : "Nicaragua",
"NOK" : "Norway",
"NPR" : "Nepal",
"NZD" : "Cook Islands, New Zealand, Niue, Pitcairn, Tokelau",
"OMR" : "Oman",
"PAB" : "Panama",
"PEN" : "Peru",
"PGK" : "Papua New Guinea",
"PHP" : "Philippines",
"PKR" : "Pakistan",
"PLN" : "Poland",
"PYG" : "Paraguay",
"QAR" : "Qatar",
"RON" : "Romania",
"RSD" : "Serbia",
"RUB" : "Russia, Abkhazia, South Ossetia",
"RWF" : "Rwanda",
"SAR" : "Saudi Arabia",
"SBD" : "Solomon Islands",
"SCR" : "Seychelles",
"SDG" : "Sudan",
"SEK" : "Sweden",
"SGD" : "Singapore",
"SHP" : "Saint Helena",
"SKK" : "Slovakia",
"SLL" : "Sierra Leone",
"SOS" : "Somalia",
"SRD" : "Suriname",
"STD" : "São Tomé and Príncipe",
"SYP" : "Syria",
"SZL" : "Swaziland",
"THB" : "Thailand",
"TJS" : "Tajikistan",
"TMM" : "Turkmenistan",
"TND" : "Tunisia",
"TOP" : "Tonga",
"TRY" : "Turkey",
"TTD" : "Trinidad and Tobago",
"TWD" : "Taiwan and other islands that are under the effective control of the Republic of China (ROC)",
"TZS" : "Tanzania",
"UAH" : "Ukraine",
"UGX" : "Uganda",
"USD" : "American Samoa, British Indian Ocean Territory, Ecuador, El Salvador, Guam, Haiti, Marshall Islands, Micronesia, Northern Mariana Islands, Palau, Panama, Puerto Rico, East Timor, Turks and Caicos Islands, United States, Virgin Islands",
"USN" : "United States",
"USS" : "United States",
"UYU" : "Uruguay",
"UZS" : "Uzbekistan",
"VEB" : "Venezuela",
"VND" : "Vietnam",
"VUV" : "Vanuatu",
"WST" : "Samoa",
"XAF" : "Cameroon, Central African Republic, Congo, Chad, Equatorial Guinea, Gabon",
"XAG" : "",
"XAU" : "",
"XBA" : "",
"XBB" : "",
"XBC" : "",
"XBD" : "",
"XCD" : "Anguilla, Antigua and Barbuda, Dominica, Grenada, Montserrat, Saint Kitts and Nevis, Saint Lucia, Saint Vincent and the Grenadines",
"XDR" : "International Monetary Fund",
"XFO" : "Bank for International Settlements",
"XFU" : "International Union of Railways",
"XOF" : "Benin, Burkina Faso, Côte d'Ivoire, Guinea-Bissau, Mali, Niger, Senegal, Togo",
"XPD" : "",
"XPF" : "French Polynesia, New Caledonia, Wallis and Futuna",
"XPT" : "",
"XTS" : "",
"XXX" : "",
"YER" : "Yemen",
"ZAR" : "South Africa",
"ZMK" : "Zambia",
"ZWD" : "Zimbabwe"]
and some function to parse dict:
func countryBy(code : String) -> String? {
return codeToCountry[code]
}
countryBy(code: "ZWD")
countryBy(code: "")
countryBy(code: "asda")
Here it's some working example:
https://iswift.org/playground?blvcE5
The country is not unique per currency. An alternative solution can be finding currency through country first (e.g. by using this), grouping by currency, and having a list of countries using that currency. Finally, you can select a representative country for those currencies with more than one country.
Assuming a pandas DataFrame with country and currency as its columns, grouping can be done with the following:
df.groupby('currency').country.apply(list).reset_index()

Step-by-Step navigation by using GPS in iOS sdk [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want Step by Step navigation by using GPS with google Maps and how to achieve that one.
Any help really appreciated
Thank you
you need a google API Services and they provide full Route path when you give Startpoint and Destination point and call the api with the following
http://maps.google.com/maps/api/directions/json?sensor=true&origin=23.027439,72.523089&destination=23.029108,72.507570
here my startingpoint is origin=23.027439,72.523089 and destintaion is destination=23.029108,72.507570
so now google will provide following data
{
"routes" : [
{
"bounds" : {
"northeast" : {
"lat" : 23.0296906,
"lng" : 72.5234184
},
"southwest" : {
"lat" : 23.026354,
"lng" : 72.50715599999999
}
},
"copyrights" : "Map data ©2014 Google",
"legs" : [
{
"distance" : {
"text" : "2.2 km",
"value" : 2249
},
"duration" : {
"text" : "5 mins",
"value" : 325
},
"end_address" : "Sarkhej - Gandhinagar Highway, Satellite, Ahmedabad, Gujarat 380054, India",
"end_location" : {
"lat" : 23.0290924,
"lng" : 72.5076297
},
"start_address" : "38, Indus Park, Satellite, Ahmedabad, Gujarat 380015, India",
"start_location" : {
"lat" : 23.027439,
"lng" : 72.5230894
},
"steps" : [
{
"distance" : {
"text" : "68 m",
"value" : 68
},
"duration" : {
"text" : "1 min",
"value" : 24
},
"end_location" : {
"lat" : 23.0269233,
"lng" : 72.5227287
},
"html_instructions" : "Head \u003cb\u003esouthwest\u003c/b\u003e toward \u003cb\u003eSatellite Rd\u003c/b\u003e",
"polyline" : {
"points" : "oppkCitsyLXPJFh#\\VN"
},
"start_location" : {
"lat" : 23.027439,
"lng" : 72.5230894
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "85 m",
"value" : 85
},
"duration" : {
"text" : "1 min",
"value" : 30
},
"end_location" : {
"lat" : 23.0265039,
"lng" : 72.5234184
},
"html_instructions" : "Turn \u003cb\u003eleft\u003c/b\u003e onto \u003cb\u003eSatellite Rd\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003ePass by Hanuman Mandir (on the left)\u003c/div\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "gmpkCarsyLVa#`#u#Pc#FM"
},
"start_location" : {
"lat" : 23.0269233,
"lng" : 72.5227287
},
"travel_mode" : "DRIVING"
},
you have to understand the documentation for using google direction services for that here is the link https://developers.google.com/maps/documentation/javascript/directions.
here is a simple logic you can use after that.
what you have to do is to store this steps dictionaryArray in array and then try to fetch it one by one.
Check didUpdateToLocation method for current Lat Long and if your current location is near by the vlaue of step Dcitionay's endLocation point and if its near by then you can alert the message of html_instructions Value that which direction user has to go next and increase your index for steps array dictionary and same do it for the last index of steps.
if need any help feel free to ask.

Resources