I need to be able to get a list of nearby places within my app. I want this to be inside a NavigationDrawer as well. Just like Google Now's Nearby Places card:
Although I want this to be wrapped inside a NavigationDrawer. Any way to do this?
Thanks.
Google Places API is a web-based sevice, so you need to send a request to:
https://maps.googleapis.com/maps/api/place/search/json
?location=COORDINATES_IN_LAT_LONG
&radius=DISTANCE_IN_METERS
&key=YOUR_API_KEY
The result you will get back will be in JSON which is fairly easy to parse using GSON:
{
"html_attributions" : [],
"results" : [
{
"geometry" : {
"location" : {
"lat" : 37.79593620000001,
"lng" : -122.40000320
},
"viewport" : {
"northeast" : {
"lat" : 37.80475270,
"lng" : -122.38399580
},
"southwest" : {
"lat" : 37.78711860,
"lng" : -122.41601060
}
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
"id" : "7498697d87cb1a28280277cb7825e0a4c21387d6",
"name" : "Financial District",
"reference" : "CoQBegAAAFrgJ9ZyeZrV_a9QWteNl9hrNGq-9qhPIP0M9yIL00HhKzBJNERhX95nEnAAtgBKqc2e51Yq2-OG3g-D8YZ20pcFKK7n3Pipd3Rpz7JmFedlg-gimYv3YGhOYVhblHYhhJM8y48J7tbDT4QPKsnumhsyhTf-5YktikanlFKt3NKNEhDwKmUyXRDhsYS1-rzHCZSRGhQP5VmDcuvvxvYE7e7dC-0PWYhfjw",
"types" : [ "neighborhood", "political" ],
"vicinity" : "San Francisco"
},
{
"geometry" : {
"location" : {
"lat" : 37.7856560,
"lng" : -122.4012520
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/art_gallery-71.png",
"id" : "5e693f5ae4f1cd1512732b1568ff0e4b67ab0291",
"name" : "San Francisco Museum of Modern Art",
"rating" : 4.30,
"reference" : "CpQBgQAAAO9fVOGklWz3ugJeJ0DuVibD60yFJ_z19hm5Cm7f4NYsIECaVqC2yhQ746w2vMmAJmA-jYNNwp5_ot7hsRxVmcbO1TdvBtYG3LZ6JD2vxgMXSCFK3U2McAywoOsbPwjU-9fN6jtHmvuiCXNDamIUP4IX462NsmyO06digENJcMoLES75jTTvVBjuRvNFRdIJnRIQDtf7lhNra8eTmAYy1PKKnhoU7hDZ-Y6TB8HRnHBsVDnsWnL5E0o",
"types" : [ "art_gallery", "store", "establishment" ],
"vicinity" : "151 Third Street, San Francisco"
},
{
"geometry" : {
"location" : {
"lat" : 37.7791590,
"lng" : -122.4158080
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/library-71.png",
"id" : "b1c83827c82c9fa59ffcdad652d1e8a1b04a4ae8",
"name" : "San Francisco Public Library",
"rating" : 4.20,
"reference" : "CoQBewAAAP-wCLLWVV2kys-vTPPr9LZPUkZXqrUUjG6LTRmcVARlehuh_SkvisDlH5X6WgoX6BG16e7RSS94xxhZbj0B3i7gC1KFDz_Oc88hK6YUj3w8Ix0N5M6UmKfAIXq1CYXLMrt_KAR7WsNF65MiSnj-Nqu0AMxwW-dMvRfmHOk7xGW0EhCyRZgNzYmPV08XAHZ-HBx_GhQYlLxuAU4MH8FvkdMWbQ1Xvf7WxA",
"types" : [ "library", "establishment" ],
"vicinity" : "100 Larkin Street, San Francisco"
},
You can then pass it to the adapter of your navigation drawer, if you so choose. If you want to show this data in the navigation drawer even in offline mode, cache this data in a txt file and read it on starting the app. This will also have the added advantage of saving bandwidth by refreshing this data only when the user chooses so.
If you want places ranked by distance, add &rankby=distance to your request URL.
Source
Related
I'm working on an android app with palces and routes. I have generated an url with origin, destination, waypoints optimizing the route with the API.
This is the code:
String url = "https://maps.googleapis.com/maps/api/directions/json?origin=" + origen +
"&destination=" + destination +
"&waypoints=optimize:true" + waypoints +
"&key=" + MAPS_API_KEY;
With this url I get a JSON response
"geocoded_waypoints" : [
{
"geocoder_status" : "OK",
"place_id" : "ChIJg7rCFwEtQg0Rxe4x4GA7l1o",
"types" : [ "street_address" ]
},
{
"geocoder_status" : "OK",
"place_id" : "ChIJP2o6r25hLxMR_QZrIrfaJTc",
"types" : [ "street_address" ]
},
{
"geocoder_status" : "OK",
"place_id" : "ChIJg7rCFwEtQg0Rxe4x4GA7l1o",
"types" : [ "street_address" ]
}
],
"routes" : [
{
"bounds" : {
"northeast" : {
"lat" : 44.4292807,
"lng" : 12.6160845
},
"southwest" : {
"lat" : 40.519053,
"lng" : -3.6181872
}
},
"copyrights" : "Map data ©2022 Google, Inst. Geogr. Nacional",
"legs" : [
{
"distance" : {
"text" : "1.946 km",
"value" : 1946454
},
"duration" : {
I thought with this url Google Maps would be open automatically with the optimized route, but it is not like this. I'm trying to find out what I should do to open goolge maps with the route, but I don't find the solution.
Someone here have the solution? Thank you!!!
I'm integrating paypal in our shopping system.
I'm using the Java Api.
In the current form the process is the following:
The user chooses paypal as payment and clicks on "Pay Order"
The Server sends a an createOrder Request with Capture Intent.
The Server receives a response with links.
The user is redirected to the "approve" link.
After finishing paypal redirects the user to the shop page with the "thanks for your order message".
All this is working as expected.
But no payment is done / no money transfered.
What am I doing wrong here?
Thanks in advance!
For reference the request/response:
Request: {}, {
"application_context" : {
"user_action" : "PAY_NOW",
"landing_page" : "BILLING",
"return_url" : "https://www.foobar.de.localhost:8443/payment/paypal?result=ok&order_id=MGS063464&secret=2E1C1B304178...",
"brand_name" : "<removed>",
"cancel_url" : "https://www.foobar.de.localhost:8443/payment/paypal?result=cancel&order_id=MGS063464",
"shipping_preference" : "SET_PROVIDED_ADDRESS"
},
"purchase_units" : [ {
"amount" : {
"breakdown" : {
"shipping" : {
"value" : "3",
"currency_code" : "EUR"
},
"item_total" : {
"value" : "2.45",
"currency_code" : "EUR"
}
},
"value" : "5.45",
"currency_code" : "EUR"
},
"reference_id" : "MGS063464",
"shipping" : {
"address" : {
"country_code" : "DE",
"address_line_1" : "<removed>",
"admin_area_2" : "<removed>",
"postal_code" : "<removed>"
},
"name" : {
"full_name" : "<removed>"
}
},
"description" : "<removed>,
"items" : [ {
"quantity" : "1",
"name" : "<removed>",
"unit_amount" : {
"value" : "2.45",
"currency_code" : "EUR"
},
"sku" : "OCI08"
} ]
} ],
"intent" : "CAPTURE"
}
Response: {}, {
"create_time" : "2021-03-14T10:52:46Z",
"purchase_units" : [ {
"payee" : {
"email_address" : "<removed>",
"merchant_id" : "L4EC8HB5DTVSC"
},
"amount" : {
"breakdown" : {
"shipping" : {
"value" : "3.00",
"currency_code" : "EUR"
},
"item_total" : {
"value" : "2.45",
"currency_code" : "EUR"
}
},
"value" : "5.45",
"currency_code" : "EUR"
},
"reference_id" : "MGS063464",
"shipping" : {
"address" : {
"country_code" : "DE",
"address_line_1" : "<removed>",
"admin_area_2" : "<removed>",
"postal_code" : "<removed>"
},
"name" : {
"full_name" : "<removed>"
}
},
"description" : "<removed>",
"items" : [ {
"quantity" : "1",
"name" : "<removed>",
"unit_amount" : {
"value" : "2.45",
"currency_code" : "EUR"
},
"sku" : "OCI08"
} ]
} ],
"links" : [ {
"method" : "GET",
"rel" : "self",
"href" : "https://api.sandbox.paypal.com/v2/checkout/orders/5MY66978KX626104P"
}, {
"method" : "GET",
"rel" : "approve",
"href" : "https://www.sandbox.paypal.com/checkoutnow?token=5MY66978KX626104P"
}, {
"method" : "PATCH",
"rel" : "update",
"href" : "https://api.sandbox.paypal.com/v2/checkout/orders/5MY66978KX626104P"
}, {
"method" : "POST",
"rel" : "capture",
"href" : "https://api.sandbox.paypal.com/v2/checkout/orders/5MY66978KX626104P/capture"
} ],
"id" : "5MY66978KX626104P",
"intent" : "CAPTURE",
"status" : "CREATED"
}
You are missing an API call, step 5 should instead be: The Server sends a Capture Order request.
Your final Step 6 should be to thank the buyer only if the capture was successful
See 'Capture Order' in the documentation.
Redirecting to an "approve" link is an old integration method, for old websites. For a modern user experience you should keep your page loaded (not redirect away) by changing your 'Create Order' and 'Capture Order' to be two server routes that return only JSON data (no other HTML or text)
Pair those routes with the following approval flow: https://developer.paypal.com/demo/checkout/#/pattern/server
Ok so I am making API requests to retrieve certain things like movies, songs, or to ping the server. However all of these responses are contained within the same response JSON object that has varying fields depending on the response. Below are three examples.
ping
{
"response" : {
"status" : "ok",
"version" : "0.9.1"
}
}
getIndexes
{
"response" : {
"status" : "ok",
"version" : "0.9.1",
"indexes" : {
"index" : [ {
"name" : "A",
"movie" : [ {
"id" : "150",
"name" : "A Movie"
}, {
"id" : "2400",
"name" : "Another Movie"
} ]
}, {
"name" : "S",
"movie" : [ {
"id" : "439",
"name" : "Some Movie"
}, {
"id" : "209",
"name" : "Some Movie Part 2"
} ]
} ]
}
}
}
getRandomSongs
{
"response" : {
"status" : "ok"
"version" : "0.9.1"
"randomSongs" : {
"song": [ {
"id" : "72",
"parent" : "58",
"isDir" : false,
"title" : "Letter From Yokosuka",
"album" : "Metaphorical Music",
"artist" : "Nujabes",
"track" : 7,
"year" : 2003,
"genre" : "Hip-Hop",
"coverArt" : "58",
"size" : 20407325,
"contentType" : "audio/flac",
"suffix" : "flac",
"transcodedContentType" : "audio/mpeg",
"transcodedSuffix" : "mp3",
"duration" : 190,
"bitRate" : 858,
"path" : "Nujabes/Metaphorical Music/07 - Letter From Yokosuka.flac",
"isVideo" : false,
"created" : "2015-06-06T01:18:05.000Z",
"albumId" : "2",
"artistId" : "0",
"type" : "music"
}, {
"id" : "3135",
"parent" : "3109",
"isDir" : false,
"title" : "Forty One Mosquitoes Flying In Formation",
"album" : "Tame Impala",
"artist" : "Tame Impala",
"track" : 4,
"year" : 2008,
"genre" : "Rock",
"coverArt" : "3109",
"size" : 10359844,
"contentType" : "audio/mpeg",
"suffix" : "mp3",
"duration" : 258,
"bitRate" : 320,
"path" : "Tame Impala/Tame Impala/04 - Forty One Mosquitoes Flying In Formation.mp3",
"isVideo" : false,
"created" : "2015-06-29T21:50:16.000Z",
"albumId" : "101",
"artistId" : "30",
"type" : "music"
} ]
}
}
}
So basically my question is, how should I structure my model classes to use for parsing these responses? At the moment I have an abstract response object that only contains fields for the status and version. However, by using this approach I will need a response class that extends this abstract class for ever request I make (e.g. AbstractResponse, IndexesResponse, RandomSongsResponse). Also, some models with the same name may have different fields depending on the API request made. I would prefer to avoid making a model class for every possible scenario.
And as an extra note, I am using GSON for JSON serialization/deserialization and Retrofit to communicate with the API.
I'm having an issue in STS creating a custom template. What I want is the ability to do token-based replacement within all files in the project. I've read this is possible with the "token" replacement, but cannot seem to get the wizard.json to let me accept multiple inputs. The "example" you see everywhere is replacing the top-level-package, which I've got to work great.
Anyone have any examples of doing multiple inputs in the wizard.json, or have any idea on what I'm doing wrong?
Here is what I have, which doesn't work:
{
"info" : {
"elements" : {
"element" : [
{
"name" : "mysystem",
"description" : "Please the name of your system (ex. marketing, hr, accounting, etc).",
"type" : "java.lang.String",
"page" : 0,
"required" : true,
"pattern" : "\\w+",
"replaceKind" : "token"
}
],
"element" : [
{
"name" : "myapp",
"description" : "Please the name of your application (ex. thisapplication, thatapplication, etc).",
"type" : "java.lang.String",
"page" : 0,
"required" : true,
"pattern" : "\\w+",
"replaceKind" : "token"
}
]
},
"projectName" : "projectName",
"pages" : {
"page" : [
{
"order" : 0,
"description" : "System Info"
}
]
}
}
}
The "myapp" picks up and does the translation, but the "mysystem" never even gets displayed for input (screen one is just the myapp text).
For those who run into the same problem, I have figured this out. Here is what I ended up with.
{
"info" : {
"elements" : {
"element" : [
{
"name" : "mysystem",
"description" : "Please the name of your system (ex. marketing, hr, accounting, etc).",
"type" : "java.lang.String",
"page" : 0,
"required" : true,
"pattern" : "\\w+",
"replaceKind" : "token"
},
{
"name" : "myapp",
"description" : "Please the name of your application (ex. thisapplication, thatapplication, etc).",
"type" : "java.lang.String",
"page" : 1,
"required" : true,
"pattern" : "\\w+",
"replaceKind" : "token"
}
]
},
"projectName" : "projectName",
"pages" : {
"page" : [
{
"order" : 0,
"description" : "System Info"
}
],
"page" : [
{
"order" : 1,
"description" : "System Info 2"
}
]
}
}
}
How can I navigate JSON string from one key to another nested key and get the value? I have the following string
{ "data" : { "current_condition" : [ { "cloudcover" : "75",
"humidity" : "29",
"observation_time" : "07:59 PM",
"precipMM" : "0.0",
"pressure" : "1011",
"temp_C" : "19",
"temp_F" : "67",
"visibility" : "16",
"weatherCode" : "116",
"weatherDesc" : [ { "value" : "Partly Cloudy" } ],
"weatherIconUrl" : [ { "value" : "http://www.worldweatheronline.com/images/wsymbols01_png_64/wsymbol_0002_sunny_intervals.png" } ],
"winddir16Point" : "N",
"winddirDegree" : "350",
"windspeedKmph" : "26",
"windspeedMiles" : "16"
} ],
"request" : [ { "query" : "01801",
"type" : "Zipcode"
} ],
"weather" : [ { "date" : "2011-05-09",
"precipMM" : "0.0",
"tempMaxC" : "19",
"tempMaxF" : "65",
"tempMinC" : "10",
"tempMinF" : "50",
"weatherCode" : "113",
"weatherDesc" : [ { "value" : "Sunny" } ],
"weatherIconUrl" : [ { "value" : "http://www/images/wsymbols01_png_64/wsymbol_0001_sunny.png" } ],
"winddir16Point" : "NNW",
"winddirDegree" : "348",
"winddirection" : "NNW",
"windspeedKmph" : "24",
"windspeedMiles" : "15"
},
{ "date" : "2011-05-10",
"precipMM" : "0.1",
"tempMaxC" : "13",
"tempMaxF" : "56",
"tempMinC" : "12",
"tempMinF" : "53",
"weatherCode" : "122",
"weatherDesc" : [ { "value" : "Overcast" } ],
"weatherIconUrl" : [ { "value" : "http://www/images/wsymbols01_png_64/wsymbol_0004_black_low_cloud.png" } ],
"winddir16Point" : "NNE",
"winddirDegree" : "12",
"winddirection" : "NNE",
"windspeedKmph" : "31",
"windspeedMiles" : "19"
}
]
} }
So I answer my own question:
In case someone else want to get value quickly: This is what I was looking for.
JSONObject j = new JSONObject(strResponse);
String weatherDesc = jObject.getJSONObject("data").getJSONArray("weather").getJSONObject(0).getJSONArray("weatherDesc").getJSONObject(0).getString("value");
There are JSON libraries in pretty much any language. If you suggest one, I might be able to point you to something.
In the meantime, here are a few:
Perl JSON library
Python's is built in
Javascript serializes its objects in JSON so it's super easy
C# library -- also see C# - parsing json formatted data into nested hashtables
Here's the Android JSON reference
And so on. I suggest a quick google for the language of your choice.
Generally speaking you will use a library that is already built specifically for you language, what language are you trying to read the data in? Many languages have a couple of libraries available, some languages may have built in support, like JavaScript.
if you just need to understand the data, it is pretty readable...