Read JSON data returned by google maps - blackberry

In my app I use the BlackBerry API to get latitude and longitude. I would like to do reverse geocoding using Google maps by creating an http connection. How do I parse the data, and then read a specific element, such as the address?
An example URL:
http://maps.google.com/maps/geo?json&ll=9.6,73.7
Gives response:
{
"name": "9.600000,76.760000",
"Status": {
"code": 200,
"request": "geocode"
},
"Placemark": [ {
"id": "p1",
"address": "Kanjirappalli Elikkulam Rd, Kerala, India",
"AddressDetails": {
"Accuracy" : 6,
"Country" : {
"AdministrativeArea" : {
"AdministrativeAreaName" : "Kerala",
"SubAdministrativeArea" : {
"SubAdministrativeAreaName" : "Kottayam",
"Thoroughfare" : {
"ThoroughfareName" : "Kanjirappalli Elikkulam Rd"
}
}
},
"CountryName" : "India",
"CountryNameCode" : "IN"
}

Use the JSON ME library. See Using JSON in Java ME for examples of how to use it.

Related

How to fetch "#microsoft.graph.downloadUrl" from Microsoft Search API?

I am using Microsoft Search API to search for files in SharePoint, objective is to fetch temporary url ("#microsoft.graph.downloadUrl") amoung other fields. I have used below search request,
Url - POST request: https://graph.microsoft.com/v1.0/search/query
Body:
{
"requests": [
{
"entityTypes": [
"driveItem"
],
"query": {
"queryString": "search-value",
"query": "path:\"https://{company}.sharepoint.com/sites/{site}/shared\""
},
"fields": [
"name",
"webUrl",
"#microsoft.graph.downloadUrl"
]
}
]
}
The result returned is below, and it is missing "#microsoft.graph.downloadUrl" field.
"moreResultsAvailable": false,
"hits": [
{
"hitId": "01CDLPULQVGFRNVHYTJVFL3NPPXIGOUDUS",
"rank": 1,
"summary": "string;#<c0>search-value</c0> <c0>search-value</c0> Internal 1 0 search-value Graph explorer {DA623115<ddd/>",
"resource": {
"#odata.type": "#microsoft.graph.driveItem",
"name": "word.docx",
"webUrl": "https://company.sharepoint.com/sites/{site}/Cases/search-value/word.docx"
}
},
Search API can retrieve only properties but not instance attributes like "#microsoft.graph.downloadUrl".
Properties
Instance attributes
I think there's no need to use the REST API. To get the temporary #microsoft.graph.downloadUrl download link I used the following to get the value:
var selectedFile = files.value[0];
var downloadLink = selectedFile["#microsoft.graph.downloadUrl"];
Found at this link: https://github.com/OneDrive/onedrive-api-docs/issues/547
I hope this helps

Authorize.net payment gateway Charge a Credit Card API for iOS swift

hello everyone as i am using payment gateway charge credit api but i am getting error while passing json object to api.and here my original JSON object which pass to charge credit api.
{
"createTransactionRequest": {
"merchantAuthentication": {
"name": "XXXXXX",
"transactionKey": "XXXXXXXX"
},
"refId": "123456",
"transactionRequest": {
"transactionType": "authCaptureTransaction",
"amount": "5",
"payment": {
"creditCard": {
"cardNumber": "5424000000000015",
"expirationDate": "2020-12",
"cardCode": "999"
}
}
}
}
}
this is original json request
but in iOS while making JSON we get below JSON object and sequence of JSON object are change that's why we getting error from api.
{
"createTransactionRequest": {
"merchantAuthentication": {
"name": "XXXXXX",
"transactionKey": "XXXXXXX"
},
"refId": "123456",
"transactionRequest": {
"amount": "5",
"payment": {
"creditCard": {
"cardCode": "999",
"cardNumber": "5424000000000015",
"expirationDate": "2020-12"
}
},
"transactionType": "authCaptureTransaction"
}
}
}
after passing this JSON object to API, we will get bellow error
{
"messages": {
"resultCode": "Error",
"message": [
{
"code": "E00003",
"text": "The element 'transactionRequest' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd' has invalid child element 'amount' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'. List of possible elements expected: 'transactionType' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'."
}
]
}
}
here is my code for creating JSON object in app
var dict = Dictionary<String, Any>()
dict=[
"merchantAuthentication": [
"name": "xxxxxxx",
"transactionKey": "xxxxxxx"
],
"refId": "5656",
"transactionRequest": [
"transactionType": "authCaptureTransaction",
"amount": "55",
"payment": [
"creditCard": [
"cardNumber": "4111111111111111",
"expirationDate": "2020-12",
"cardCode": "999"
]
]
]
]
after print this JSON sequence are changed
Have you read the documentation? It's very clear from the linked page that what you're running into is a side effect of their translation of JSON elements to XML elements in the backend, specifically around the ordering of parameters in your JSON request:
A Note Regarding JSON Support
The Authorize.Net API, which is not
based on REST, offers JSON support through a translation of JSON
elements to XML elements. While JSON does not typically require a set
order to the elements in an object, XML requires strict ordering.
Developers using the Authorize.Net API should force the ordering of
elements to match this API Reference.
Their examples below this block also show that their transactionType parameters appear as the first attribute in the transactionRequest object. Tl;dr - move your transactionType parameter up in your transactionRequest object:
{
"createTransactionRequest": {
"merchantAuthentication": {
"name": "XXXXXX",
"transactionKey": "XXXXXXX"
},
"refId": "123456",
"transactionRequest": {
"transactionType": "authCaptureTransaction",
"amount": "5",
"payment": {
"creditCard": {
"cardCode": "999",
"cardNumber": "5424000000000015",
"expirationDate": "2020-12"
}
}
}
}
}
please try with following code.
let merchantSub = ["name": "XXXXXX",
"transactionKey": "XXXXXXX"]
let childCreditCard = ["cardCode": "999",
"cardNumber": "5424000000000015",
"expirationDate": "2020-12"]
let creditCard = ["creditCard":childCreditCard]
let transactionRequest = ["amount": "",
"payment":creditCard,
"transactionType":""] as [String : Any]
let merchantAuthentication = ["merchantAuthentication" :merchantSub,
"refId" : "123456",
"transactionRequest":transactionRequest] as [String : Any]
let param = ["createTransactionRequest" : merchantAuthentication]
if let data = try? JSONSerialization.data(withJSONObject: param, options: .prettyPrinted),
let str = String(data: data, encoding: .utf8) {
print(str)
}
However I recommend to use class but for initial level do like this.

Titanium- Post request is not working when I using JSONArray in body content

Hi I am sending POST request using HTTPClient. Here I am passing some JSON data which have some arrays.
{
"pccpId": "11111",
"courseId": "XXXXX",
"employeeId": "XXXXXX",
"userId": "X!##$",
"assignments": [
{
"Id": "XXXX",
"targetDate": "05/30/2018",
"targetNewDate": "04/30/2018"
},
{
"Id": "YYYYY",
"targetDate": "04/22/2018",
"targetNewDate": "04/26/2018"
}
]
}
When I am using this data, I am getting 400 error code. When I am checking with backend is not at all hitting to the server. Same data giving expected result when I run on Postman.
Anyone have any suggestion!!
Thanks
I have this pb with titanium nodeJS api, workaround is to stringify your data and parse it on server
Try to but your keys without double quotation like this
{
pccpId: "11111",
courseId: "XXXXX",
employeeId: "XXXXXX",
userId: "X!##$",
assignments: [{
"Id": "XXXX",
"targetDate": "05/30/2018",
"targetNewDate": "04/30/2018"
},
{
"Id": "YYYYY",
"targetDate": "04/22/2018",
"targetNewDate": "04/26/2018"
}
]
}

How to get nearby places from Google SDK using iOS and Swift?

How I can get nearby location from Google SDK in iOS and Swift? I need all nearby places without any type and category?
Client don't want use this url: https://maps.googleapis.com/maps/api/place/search/json?location=lat,long&radius=1000&sensor=true&key=key
You can simply do this with this API call:
https://maps.googleapis.com/maps/api/distancematrix/json?origins=51.226531,4.190688&destinations=51.114476,4.139618|51.148123,4.182590
There are three parameters in this URL,
JSON is used to return the response
origins contain the long and lat of the current location of the user and
destination contains all the addresses form which you want to find the nearest distance. the addresses will be in long and lat format and are separated by "|".
The response will be as follow
{
"destination_addresses" : [
"Dorpstraat 70, 9140 Temse, België",
"Eigenlostraat 38, 9100 Sint-Niklaas, België"
],
"origin_addresses" : [ "Provinciale Baan 37, 9120 Beveren, België" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "16,3 km",
"value" : 16346
},
"duration" : {
"text" : "22 min.",
"value" : 1321
},
"status" : "OK"
},
{
"distance" : {
"text" : "10,5 km",
"value" : 10521
},
"duration" : {
"text" : "17 min.",
"value" : 1003
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
All you have to do is to get the nearest destination on the time basis .
Cheers

Can Geofire query location if it's a child key of an autoID?

According to GeoFire, it allows you to query all keys within a geographic area. If that's the case, can I query for object locations if location is a child key of an autoID?
Basically, I want to query for all messages within a geographic radius, and then sort them by recency. Is autoID the best key to use for identifying many objects? Let's say I have 100 messages in a defined radius, how would I identify them and subsequently retrieve them?
{
"Messages" : {
"-KFGX5H3rLSnpPvupakm" : {
"message" : "Concert at the park!",
"location" : {
"g" : "xxxx",
"l" : {
"0": "xxx",
"1": "xxx"
}
},
},
"-KFGZkwAIl817CLDLmMp" : {
"message" : "It's gonna be a foggy one.",
"location" : {
"g" : "xxxx",
"l" : {
"0": "xxx",
"1": "xxx"
}
},
}
}
}

Resources