I have an address field in my app where the user needs to enter the required address. I have used google Geocoder to get the GPS coordinates of the address . But now I want to make it easier for the user by using Places Autocomplete . But Places Autocomplete only returns the address , Id and reference of the place .
Is there a way to get the GPS coordinates of the address selected by the user using Places Autocomplete API ? Do I have to use Geocoder again after the user selects his address from Places Autocomplete ?
Or Should I use Places API again after the user selects his address to get the GPS coordinates of the address ? I dont want to send multiple requests to the Places API because of the usage limits in place . . This is the expected response from Places API ..There is no GPS coordinates in the response .
"status": "OK",
"predictions": [ {
"description": "Paris, France",
"id" : "691b237b0322f28988f3ce03e321ff72a12167fd",
"reference": "CiQYAAAA0Q_JA...kT3ufVLDDvTQsOwZ_tc",
"terms": [ {
"value": "Paris",
"offset": 0
}, {
"value": "France",
"offset": 7
} ],
"types": [ "geocode" ],
"matched_substrings": [ {
"offset": 0,
"length": 5
} ]
}, {
"description": "Paris, TX, United States",
"id" : "518e47f3d7f39277eb3bc895cb84419c2b43b5ac",
"reference": "CjQjAAAAHnbxZZ...BDR3iIOFdMTxwo1jHg",
"terms": [ {
"value": "Paris",
"offset": 0
}, {
"value": "TX",
"offset": 7
}, {
"value": "United States",
"offset": 11
} ],
"types": [ "geocode" ],
"matched_substrings": [ {
"offset": 0,
"length": 5
} ]
}, {
"description": "Paris, Ontario, Canada",
"id" : "e7ac9c89d4a590305242b0cb5bf43064027223c9",
"reference": "CjQhAAAAIv_YWYt...F8KZHY36TwMrbyu_g",
"terms": [ {
"value": "Paris",
"offset": 0
}, {
"value": "Ontario",
"offset": 7
}, {
"value": "Canada",
"offset": 16
} ],
"types": [ "geocode" ],
"matched_substrings": [ {
"offset": 0,
"length": 5
} ]
}
You simply use the Place Details part of the Places API where you get the actual place from the reference in each suggestion using the "reference" value. For example:
https://maps.googleapis.com/maps/api/place/details/json?reference=CiQYAAAA0Q_JA...kT3ufVLDDvTQsOwZ_tc&sensor=true&key=AddYourOwnKeyHere
This will give you information about the place including its coordinates (point for a specific location, bounds for an area).
Related
i have some response form HTTP API - GeoJSON data, but how i can get only some values from features --> properties in Kotlin - Android Studio? Or is there some statement where I can determine for example all object where "year==2014" to array/list? So i want only some properties to array/list or variable. Thank you for your help :)
This working, but how to loop for each properties?
val test = jsonObject.getJSONArray("features").getJSONObject(0).getJSONObject("properties").getString("year")
{
"type": "FeatureCollection",
"name": "cycl_accidents_cycl_neh_xytabletopoint_spa1",
"crs": { "crs".
"type": "name",
"properties": { "properties".
"name": "urn:ogc:def:crs:OGC:1.3:CRS84"
}
},
"features": [
{
"type": "feature",
"properties": {
"objectid": 1,
"join_count": 1,
"target_fid": 1,
"id": 60040140073.0,
"d": -604774.832,
"e": -1162719.75,
"datum": "2014-08-03T00:00:00Z",
"day": 7,
"year": 2014,
"month": 8,
"collision": "other type of accident",
"cause": "driving on the wrong side of the road, driving into oncoming traffic",
"alcohol": "Yes, blood alcohol content between 0,8‰ and 1,0‰",
"at fault": "driver of a non-motor vehicle",
'consequences': 'accident resulting in death or injury',
'road condition': 'surface dry, not contaminated',
'weather conditions': 'not obstructed',
'visibility': 'at night - no public lighting, visibility not impaired by weather conditions',
'visibility': 'good',
'mishap': 'none or none of the above',
"type_of_community": "road monitored (in selected cities)",
'type of vehicle': 'bicycle',
'rider_status': 'under the influence of alcohol, blood alcohol content up to 0,99 ‰',
"affected_ride": 1,
"person": "driver",
"mark_person": "without helmet (only for motorcyclists or cyclists)",
"gender": "male",
"consequence": "slight injury",
"killed_os": 0,
"severely_injured_os": 0,
"slightly_injured_os": 1,
"material damage": 0,
"time": 430,
"hour": 4,
"month_t": "august",
"day of the week": "Sunday",
"age_group": "19-24",
"name": "Brno-Bosonohy",
"point_x": 16.52074206,
"point_y": 49.17113043000001,
"globalid": "{CD1B3254-7DD0-478E-8B3A-C6221ADC3DAB}"
},
"geometry": {
"type": "point",
"coordinates": [
16.520742066000025,
49.171130437000045
]
}
},
{
"type": "Feature",
"properties": {
"objectid": 2,
"join_count": 1,
"target_fid": 2,
"id": 60206100089.0,
"d": -596241.506,
"e": -1157759.125,
"datum": "2010-01-21T00:00:00Z",
"day": 4,
"year": 2010,
"month": 1,
"collision": "collision with a moving non-rail vehicle",
"cause": "driver not fully engaged in driving the vehicle",
"alcohol": "No",
"at fault": "by the driver of the motor vehicle",
'consequences': 'accident resulting in death or injury',
'road condition': 'surface dry, dirty (sand, dust, leaves, gravel, etc.)',
'weather conditions': 'not obstructed',
'visibility': 'at night - with public lighting, visibility not impaired by weather conditions',
'visibility': 'good',
'accident location': 'near a pedestrian crossing (within 20 m)',
'road type': 'local road',
'type of vehicle': 'bicycle',
'condition_ridic': 'good - no adverse circumstances detected',
"affected_ridice": 1,
"person": "driver",
"person_mark": "with helmet (only for motorcyclists or cyclists)",
"gender": "male",
"consequence": "slight injury",
"killed_os": 0,
"severely_injured_os": 0,
"slightly_injured_os": 1,
"material damage": 20,
"time": 1829,
"hour": 18,
"month_t": "January",
"day of the week": "Thursday",
"age_group": "33-44",
"name": "Brno-sever",
"point_x": 16.62980964,
"point_y": 49.22375737,
"globalid": "{83269995-7595-4174-B258-92B2231CF8F2}"
},
"geometry": {
"type": "point",
"coordinates": [
16.629809646000069,
49.223757371000033
]
}
},
]
}
I am assuming features is the list which you get after parsing your response.
first parse your response to your model class. please check this link
for that.
https://stackoverflow.com/a/68501606/7248394.
for example
val apiData = Gson().fromJson(readJson, YourModelClass::class.java)
val features = apiData.features
val featureList = features.filter{
it.properties.year =="2014"
}
so this will give featureList of 2014 year.
Thanks in Advance. This is the response what i am getting. I need to insert this data to local database using room library and need to use auto synchronization in android.
I need to create a local database with this data . I am not clear how to save list and List in android.
{"email": "abc#gmail.com",
"createdOn": "1530344810442",
"childname": "kid1",
"statuscode": "Open",
"programs": ["a","b"],
"labels": [
"5b360152a987ba31b26ced9d",
"5b360152a987ba31b26ced98"
],
"enquiriedPrograms": [
"FIRST",
"Daycare"
],
"details": "Rosy [11:53 a.m. 10 Mar 2018 ] - Interested to join in next year",
"dateofenquiry": "1520682660000",
"followup": "1552132380000",
"channel": "Parent referral",
"academicYear": "2019-20",
"childDOB": "959668410000",
"country": "India",
"countryCode": "91",
"country_name_code": "IN",
"secodaryContact": "99563959718",
"secodaryCountry": "India",
"secodaryCountryCode": "91",
"secodarycountry_name_code": "IN",
"priority": "0",
"_id": "5b37356afa4f6c15a0474d08",
"parentname": "parent",
"mobile": "96542372812",
"schoolid": "59df41728832621654417350",
"__v": 0,
"labelNames": [
{
"_id": "5b360152a987ba31b26ced9d",
"name": "Add",
"colourCode": "#FFFF00"
},
{
"_id": "5b360152a987ba31b26ced98",
"name": "sub",
"colourCode": "#7FB3D5"
}
]
}
My JSON contains only name of the food categories, Looks like below
[
{
"cu_id": "2",
"cuisine_type": "American"
},
{
"cu_id": "24",
"cuisine_type": "Sandwich"
},
{
"cu_id": "17",
"cuisine_type": "Seafood"
},
{
"cu_id": "29",
"cuisine_type": "Sports Bar"
},
{
"cu_id": "5",
"cuisine_type": "Steak"
},
{
"cu_id": "20",
"cuisine_type": "Sushi"
}
]
I want to get default image automatically from Internet by searching 'cuisine_type', How to do that?
You can use pixabay api it's a free RESTful api for searching and retrieving free images and videos released on Pixabay under Creative Commons CC0.
Sending a GET request like this :
https://pixabay.com/api/?key={ KEY }&q=query&image_type=photo
where :
Key : the api key you get after creating an account
q : the queried object you need to look for
image_type : what kind of data you need (picture, video)
returned data will be something like this :
{
"total": 4692,
"totalHits": 500,
"hits": [
{
"id": 195893,
"pageURL": "https://pixabay.com/en/blossom-bloom-flower-yellow-close-195893/",
"type": "photo",
"tags": "blossom, bloom, flower",
"previewURL": "https://static.pixabay.com/photo/2013/10/15/09/12/flower-195893_150.jpg"
"previewWidth": 150,
"previewHeight": 84,
"webformatURL": "https://pixabay.com/get/35bbf209db8dc9f2fa36746403097ae226b796b9e13e39d2_640.jpg",
"webformatWidth": 640,
"webformatHeight": 360,
"imageWidth": 4000,
"imageHeight": 2250,
"imageSize": 4731420,
"views": 7671,
"downloads": 6439,
"favorites": 1,
"likes": 5,
"comments": 2,
"user_id": 48777,
"user": "Josch13",
"userImageURL": "https://static.pixabay.com/user/2013/11/05/02-10-23-764_250x250.jpg",
},
{
"id": 14724,
...
},
...
]
}
for more detail visit this link
I'm making a navigation application, I have a bunch of routes being returned from Googles Directions API (set alternatives to true), which the user will then choose from. What I'd like to do is launch the Map intent for Google Maps with the selected route passed in.
I'm wondering if this is possible?
I've seen examples of passing in saddr and daddr which will automatically show the best route, but instead I'd like it to display the one selected by a user from one of the direction results which may not the best (most optimum).
Thanks
After reading the google direction api, I saw that in its response type (https://developers.google.com/maps/documentation/directions/intro#sample-response), we have for every step, latitude and longitude defined.
Say your output route looks like (this is dummy, not original):
{
...
"routes": [ {
"summary": "I-40 W",
// There are many legs, but say user choses this below first leg.
"legs": [ {
"steps": [
{
"travel_mode": "DRIVING",
"start_location": {
"lat": 41.8507300,
"lng": -87.6512600
},
"end_location": {
"lat": 41.8525800,
"lng": -87.6514100
},
"polyline": {
"points": "a~l~Fjk~uOwHJy#P"
},
"duration": {
"value": 19,
"text": "1 min"
},
"html_instructions": "Head \u003cb\u003enorth\u003c/b\u003e on \u003cb\u003eS Morgan St\u003c/b\u003e toward \u003cb\u003eW Cermak Rd\u003c/b\u003e",
"distance": {
"value": 207,
"text": "0.1 mi"
}
},
{
"travel_mode": "DRIVING",
"start_location": {
"lat": 41.8107300,
"lng": -87.6012600
},
"end_location": {
"lat": 41.8725800,
"lng": -87.6414100
},
"polyline": {
"points": "a~l~Fjk~uOwHJy#P"
},
"duration": {
"value": 19,
"text": "1 min"
},
"html_instructions": "Head \u003cb\u003enorth\u003c/b\u003e on \u003cb\u003eS Morgan St\u003c/b\u003e toward \u003cb\u003eW Cermak Rd\u003c/b\u003e",
"distance": {
"value": 207,
"text": "0.1 mi"
}
}
"start_address": "Oklahoma City, OK, USA",
"end_address": "Los Angeles, CA, USA"
} ],
.... // many other legs ....
"legs":[ { ..... } ]
.
.
"copyrights": "Map data ©2010 Google, Sanborn",
...
..
.
} ]
}
]
}
Now, above for each step, we have lat and lng entries. We will use those to create our intent request.
Our request will become :
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("https://maps.google.ch/maps?saddr=Oklahoma City, OK, USA&daddr=Los Angeles, CA, USA to:41.8525800,-87.6514100 to: 41.8107300,-87.6012600"));
startActivity(intent);
Notice that I have used the steps lat and lng along with to: prefix in the url. Use can use only upto two to: prefixes in this url, because google maps app doesn't acknowledge all the waypoints but only the first and the last, when passed as intent.
To put it generalized way :
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("https://maps.google.ch/maps?saddr=[address1]&daddr=[address2] to:[address3] to: [address4]"));
startActivity(intent);
So, this will open google maps app with navigation marked from [address1] to [address2] passing through [address3] and [address4].
Hope this solves problem.
I would like to perform a request to OSM Overpass Turbo API or Overpass API from and Android Application so i can get the buildings around and area using JSON.
Something similar to
http://overpass-turbo.eu/ with the query presented below:
[out:json][timeout:25];
// gather results
(
// query part for: “building”
way["building"](37.98350674557998,23.72600823640823,37.98552989685638,23.728837966918945);
relation["building"](37.98350674557998,23.72600823640823,37.98552989685638,23.728837966918945);
);
// print results
out body;
>;
out skel qt;
The thing is that i need the results in geojson like the result below but i cannot find any query that gives me the below result.
{
"type": "FeatureCollection",
"generator": "overpass-turbo",
"copyright": "The data included in this document is from www.openstreetmap.org. The data is made available under ODbL.",
"timestamp": "2015-03-23T20:41:02Z",
"features": [
{
"type": "Feature",
"id": "relation/2604192",
"properties": {
"#id": "relation/2604192",
"building": "yes",
"type": "multipolygon"
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
23.7319885,
37.9752441
],
[
23.7319787,
37.9751612
],
[
23.7319494,
37.9751641
],
[
23.7319372,
37.9748376
],
[
23.7319702,
37.9748318
],
]
]
}
},
I get only results with nodes but not with geometry.
{
"type": "way",
"id": 25107859,
"nodes": [
2373953582,
2373953586,
2373953592,
2373953599,
2373953597,
2373953636,
2373953633,
2373953626,
273319309,
2373953582
],
"tags": {
"building": "yes"
}
},
After some useful comments (thanks scai) i found out that overpass turbo is not queried automatically. Therefore i searched for overpass api and i found out this site with a query for buildings to overpass api exporting to GeoJSON but i does not work (though the xml query in the site works but i need json). Anyone has a query that works so i can follow it?
http://inasafe.org/en/developer-docs/osm_building_downloads.html
http://overpass-api.de/api/interpreter?data=[out:json];(node[%23building%22=%22yes%22](-6.185440796831979,106.82374835014343,-6.178966266481431,106.83127999305725);way[%22building%22=%22yes%22](-6.185440796831979,106.82374835014343,-6.178966266481431,106.83127999305725);relation[%22building%22=%22yes%22](-6.185440796831979,106.82374835014343,-6.178966266481431,106.83127999305725););(._;%3E;);out%20body;