Google Directions API start_address different from origin in input - google-maps

My Google Directions API request is:
https://maps.googleapis.com/maps/api/directions/json?origin=41.43206,-81.38992&destination=41.43206,-81.48992&key=xxxxxxxx
The response I receive is:
{
...
"routes": [
{
"bounds": {
"northeast": {
"lat": 41.4358763,
"lng": -81.3897891
},
"southwest": {
"lat": 41.4238459,
"lng": -81.4910838
}
},
"copyrights": "Map data ©2016 Google",
"legs": [
{
"distance": {
"text": "6.5 mi",
"value": 10537
},
"duration": {
"text": "14 mins",
"value": 857
},
"end_address": "4743-4753 Country Ln, Warrensville Heights, OH 44128, USA",
"end_location": {
"lat": 41.4322651,
"lng": -81.4910838
},
"start_address": "45 Bell St, Chagrin Falls, OH 44022, USA",
"start_location": {
"lat": 41.4318382,
"lng": -81.3897891
},
"steps": [
{
"distance": {
"text": "0.1 mi",
"value": 191
},
"duration": {
"text": "1 min",
"value": 33
},
"end_location": {
"lat": 41.4311157,
"lng": -81.3918637
},
"html_instructions": "Head <b>southwest</b> on <b>Bell St</b> toward <b>Pleasant Dr</b>",
"polyline": {
"points": "_d{{FdmwoNFVRx#bA`EVbAVdA"
},
"start_location": {
"lat": 41.4318382,
"lng": -81.3897891
},
"travel_mode": "DRIVING"
},
...
{
"distance": {
"text": "0.2 mi",
"value": 317
},
"duration": {
"text": "1 min",
"value": 32
},
"end_location": {
"lat": 41.4322651,
"lng": -81.4910838
},
"html_instructions": "Turn <b>left</b> onto <b>Country Ln</b><div style=\"font-size:0.9em\">Destination will be on the left</div>",
"maneuver": "turn-left",
"polyline": {
"points": "ix{{FldkpNxJ?x#Ln#PnAX"
},
"start_location": {
"lat": 41.4350887,
"lng": -81.49079350000001
},
"travel_mode": "DRIVING"
}
],
"traffic_speed_entry": [],
"via_waypoint": []
}
],
"overview_polyline": {
"points": "_d{{FdmwoNvBvIVdAs#`#_Af#cCnAp#vCf#rBlAzEHd#`#nEFz#Cj#Or#{#nBUl#Q|#c#dGVZz#vAxDdGtBnDzCrEhAjCdAnCZ~Ap#bJJ`CAn#X\\\\r#hSx^hAxCn#pBXr#FbR?dCAz#ElAOhBe#xCkBvHqAtF]|BOhBG~BFpOFxBhBt\\r#vMBpA?zH?z\\CV?rV#V?nT?|QBvl##vI#lJAdI?fDDhODxPHvq#?hB_#EgA?m##EDyBBmCCqE?{FAkHB}E?cDEwBBcE?cKA_#?VdFl#fMp#pNd#fK#fJApCxJ?hB^nAX"
}
...
}
Why is the start address in the sole leg different from the origin specified in the request? These two points are 6.5 miles apart.
Same is true for end_address and destination specified in the request.
Thanks,
Abhishek Batra

The DirectionsService reverse geocodes any location provided as coordinates, finds the nearest location on the road and uses that as the origin (or destination).
Your two points both happen to be in the middle of water.

Related

Pandas json_normalize with nested JSON

I have tried many alternatives and the better result was with this statement:
json_normalize(a['solution'][0]['tour'])
I can see just one block of tours at a time. vehicle_id 0 information and I need them all together. Thank you.
The JSON is:
{
"total_clusters": 6,
"solution": [
{
"vehicles_id": "0",
"vehicles_location": {
"lat": "",
"lng": ""
},
"tour": [
{
"shipping_id": "4a4b0750-63a7-11ea-8955-43fcb2cd860a",
"type": "dropoff",
"location_id": "797",
"coordinates": {
"lat": "-34.545736",
"lng": "-58.488340"
},
"cluster": 0
},
{
"shipping_id": "75e5a2c0-6314-11ea-b657-ddd473c629a3",
"type": "dropoff",
"location_id": "114",
"coordinates": {
"lat": "-34.568707",
"lng": "-58.452963"
},
"cluster": 0
}
]
},
{
"vehicles_id": "1",
"vehicles_location": {
"lat": "",
"lng": ""
},
"tour": [
{
"shipping_id": "c83ac7c0-51c4-11ea-9aef-973de7785221",
"type": "pickup",
"location_id": "687",
"coordinates": {
"lat": "-34.592824",
"lng": "-58.375457"
},
"cluster": 1
},
{
"shipping_id": "b5a295c0-51c4-11ea-b36d-651ee769ca89",
"type": "pickup",
"location_id": "687",
"coordinates": {
"lat": "-34.592824",
"lng": "-58.375457"
},
"cluster": 1
}
]
}
]
}
Desired Output
You need to pass the record_path parameter to json_normalize.
From the docs:
record_path : str or list of str, default None
Path in each object to list of records. If not passed, data will be assumed to be an array of records.
import pandas as pd
import json
raw_json_data = """{contents_of_your_json_here}"""
json_data = json.loads(raw_json_data)
df = pd.json_normalize(json_data, ["solution", "tour"])
Result:

Google maps textsearch API is returning empty result

I'm searching for top attractions in a 'CITY_NAME' using google textsearch API. Till yesterday it was returning data but when I'm trying now it is not returning results! whats going on here, why, I'm getting ZERO_RESULTS.
Ex:
https://maps.googleapis.com/maps/api/place/textsearch/json?query=top attractions in bengaluru&language=en&key=MY_API_KEY
I'm expecting it to return results like below
{
"html_attributions": [],
"results": [
{
"formatted_address": "Mavalli, Bengaluru, Karnataka 560004, India",
"geometry": {
"location": {
"lat": 12.9507432,
"lng": 77.5847773
},
"viewport": {
"northeast": {
"lat": 12.9578032,
"lng": 77.59536344999999
},
"southwest": {
"lat": 12.9424072,
"lng": 77.57495644999999
}
}
},
"icon": "https://maps.gstatic.com/mapfiles/place_api/icons/generic_recreational-71.png",
"id": "8ae4a9c5e9c2b40e58bf0c947e5502ff9ef71c29",
"name": "Lalbagh Botanical Garden",
"opening_hours": {
"open_now": true
},
"photos": [
{
"height": 4032,
"html_attributions": [
"S.Ravindra Kumar"
],
"photo_reference": "CmRaAAAAYzPzHyHDleeTK4pM19jZ16SfDbG7lLZCrgr2wDEE_eNqDB5HdH670V0MXBRw03HH_HvFg0Rfe1dEZeG18NVVcxMUtpIOoHbN4a-csy0zqYRiJrTibapAiCxbYr8GKWrDEhBQAFmvTdSMKhoYbPlWmb-UGhSp70QBfrJgnUYSl5g_Ih24d80zIg",
"width": 3024
}
],
"place_id": "ChIJHdPykcEVrjsRIr4v35kLEY4",
"plus_code": {
"compound_code": "XH2M+7W Bengaluru, Karnataka, India",
"global_code": "7J4VXH2M+7W"
},
"rating": 4.4,
"reference": "ChIJHdPykcEVrjsRIr4v35kLEY4",
"types": [
"park",
"point_of_interest",
"establishment"
],
"user_ratings_total": 108174
},
{
.......
.......
}
]
}
But I'm getting the below response.
Response
{
"html_attributions" : [],
"results" : [],
"status" : "ZERO_RESULTS"
}
Any kind of help will much be appreciated.
Note that "attractions" is a very broad input; it can involve a wide variety of points of interests, place types etc. from museums to parks to zoos.
You should use a more specific place type in your queries. E.g.:
https://maps.googleapis.com/maps/api/place/textsearch/json?query=top%20restaurants%20in%20bengaluru&language=en&key=KEY
Hope this answers your question.

Type error: undefined is not an object(evaluating 'this.state.departure.loc.map) in React native maps

I am fetching my data from Google Directions and because the way the JSON response was set up, like this:
Object {
"geocoded_waypoints": Array [
Object {
"geocoder_status": "OK",
"place_id": "ChIJ2YDFT9zweUgRgt5Tws6n3hs",
"types": Array [
"premise",
],
},
Object {
"geocoder_status": "OK",
"place_id": "ChIJW2PCihXxeUgRRWgA9kOzpjY",
"types": Array [
"establishment",
"food",
"lodging",
"point_of_interest",
"restaurant",
],
},
],
"routes": Array [
Object {
"bounds": Object {
"northeast": Object {
"lat": 52.9242042,
"lng": -1.4751044,
},
"southwest": Object {
"lat": 52.900484,
"lng": -1.4801554,
},
},
"copyrights": "Map data ©2018 Google",
"legs": Array [
Object {
"distance": Object {
"text": "3.1 km",
"value": 3137,
},
"duration": Object {
"text": "38 mins",
"value": 2309,
},
"end_address": "Full St, Derby DE1 3AF, UK",
"end_location": Object {
"lat": 52.9242042,
"lng": -1.4756769,
},
"start_address": "50 Chatham St, Derby DE23 8TH, UK",
"start_location": Object {
"lat": 52.900484,
"lng": -1.4801443,
},
"steps": Array [
Object {
"distance": Object {
"text": "3.1 km",
"value": 3137,
},
"duration": Object {
"text": "38 mins",
"value": 2309,
},
"end_location": Object {
"lat": 52.9242042,
"lng": -1.4756769,
},
"html_instructions": "Walk to Full St, Derby DE1 3AF, UK",
"polyline": Object {
"points": "_c{aIza`Hm#BEyHC_AyAk#iCw#KCGAGAMBSFE#iBz#C#E#QDe#TMFUHWJm#TIm#k#_Em#yDuE`BIDw#SEPCJGPINILEDGFWTcBbAwB~#WJ]PIDOHWNMJ?##??#?#?#A??#?#?#A??#?#A??#A?A??#AAA?A??AA??A?AA??AI#EBGBOHo#XGBIDKBGBG#G#G#OBu#JG#KBID?A?AA??AA??AA?A?A??#A??#A??#?#?#]UGG}AiAcAu#g#a#kAw#c#Wu#_#c#U}#e#y#g#WQKGGEEAWGc#Iq#EW?k#?M#g#FoBPq#J[HSDIBGB]Ja#RcAdAYX{AdAq#Ry#Hu#BU?yA#g#AYAAIAG?CAECGACCGEEEECCEAICK?C#A#A?C#C#EDCBABCDABABCDGYgBkBwBsBw#y#GCGAYe#cAqACCAECE?C?G#Kc#NC#gBj#MDKDaBdAq#^GHCFCFCNCFEHEFwCZi##MAMCIIMOSa#Yq#Oc#Qk#CEKc#EQWuAG?ICCIAKAKKFIDIFE#OPONMLa#h#?#",
},
"start_location": Object {
"lat": 52.900484,
"lng": -1.4801443,
},
"steps": Array [
Object {
"distance": Object {
"text": "26 m",
"value": 26,
},
"duration": Object {
"text": "1 min",
"value": 17,
},
"end_location": Object {
"lat": 52.9007148,
"lng": -1.4801554,
},
"html_instructions": "Head <b>north</b> on <b>Chatham St</b> toward <b>Randolph Rd</b>",
"polyline": Object {
"points": "_c{aIza`Hm#B",
},
"start_location": Object {
"lat": 52.900484,
"lng": -1.4801443,
},
"travel_mode": "WALKING",
},
Object {
"distance": Object {
"text": "0.1 km",
"value": 126,
},
"duration": Object {
"text": "1 min",
"value": 88,
},
"end_location": Object {
"lat": 52.9007561,
"lng": -1.4782714,
},
"html_instructions": "Turn <b>right</b> onto <b>Randolph Rd</b>",
"maneuver": "turn-right",
"polyline": Object {
"points": "md{aI~a`HEyHC_A",
},
"start_location": Object {
"lat": 52.9007148,
"lng": -1.4801554,
},
"travel_mode": "WALKING",
},
Object {
"distance": Object {
"text": "0.3 km",
"value": 332,
},
"duration": Object {
"text": "4 mins",
"value": 223,
},
"end_location": Object {
"lat": 52.90362829999999,
"lng": -1.4785171,
},
"html_instructions": "Turn <b>left</b> onto <b>St Thomas Rd</b>",
"maneuver": "turn-left",
"polyline": Object {
"points": "wd{aIdv_HyAk#iCw#KCGAGAMBSFE#iBz#C#E#QDe#TMFUHWJm#T",
},
"start_location": Object {
"lat": 52.9007561,
"lng": -1.4782714,
},
"travel_mode": "WALKING",
},
Object {
"distance": Object {
"text": "0.2 km",
"value": 153,
},
"duration": Object {
"text": "2 mins",
"value": 104,
},
"end_location": Object {
"lat": 52.90412999999999,
"lng": -1.4763973,
},
"html_instructions": "Turn <b>right</b> to stay on <b>St Thomas Rd</b>",
"maneuver": "turn-right",
"polyline": Object {
"points": "uv{aIvw_HIm#k#_Em#yD",
},
"start_location": Object {
"lat": 52.90362829999999,
"lng": -1.4785171,
},
"travel_mode": "WALKING",
},
Object {
"distance": Object {
"text": "0.1 km",
"value": 129,
},
"duration": Object {
"text": "2 mins",
"value": 103,
},
"end_location": Object {
"lat": 52.9052488,
"lng": -1.4769249,
},
"html_instructions": "Turn <b>left</b> onto <b>Portland St</b>",
"maneuver": "turn-left",
"polyline": Object {
"points": "yy{aInj_HuE`BID",
},
"start_location": Object {
"lat": 52.90412999999999,
"lng": -1.4763973,
},
"travel_mode": "WALKING",
},
Object {
"distance": Object {
"text": "32 m",
"value": 32,
},
"duration": Object {
"text": "1 min",
"value": 24,
},
"end_location": Object {
"lat": 52.9055291,
"lng": -1.4768217,
},
"html_instructions": "Slight <b>right</b> at <b>Goodale St</b>",
"maneuver": "turn-slight-right",
"polyline": Object {
"points": "y`|aIvm_Hw#S",
},
"start_location": Object {
"lat": 52.9052488,
"lng": -1.4769249,
},
"travel_mode": "WALKING",
},
Object {
"distance": Object {
"text": "0.4 km",
"value": 418,
},
"duration": Object {
"text": "5 mins",
"value": 325,
},
"end_location": Object {
"lat": 52.9089381,
"lng": -1.4789711,
},
"html_instructions": "Turn <b>left</b> onto <b>Pear Tree Rd</b><div style=\"font-size:0.9em\">Go through 1 roundabout</div>",
"maneuver": "turn-left",
"polyline": Object {
"points": "qb|aIbm_HEPCJGPINILEDGFWTcBbAwB~#WJ]PIDOHWNMJ?##??#?#?#A??#?#?#A??#?#A??#A?A??#AAA?A??AA??A?AA??AI#EBGBOHo#XGBIDKBGBG#G#G#OBu#JG#KBID",
},
"start_location": Object {
"lat": 52.9055291,
"lng": -1.4768217,
},
"travel_mode": "WALKING",
},
Object {
"distance": Object {
"text": "1.0 km",
"value": 984,
},
"duration": Object {
"text": "13 mins",
"value": 760,
},
"end_location": Object {
"lat": 52.9173185,
"lng": -1.4781371,
},
"html_instructions": "At the roundabout, take the <b>1st</b> exit onto <b>Normanton Rd</b>",
"maneuver": "roundabout-left",
"polyline": Object {
"points": "{w|aIpz_H?A?AA??AA??AA?A?A??#A??#A??#?#?#]UGG}AiAcAu#g#a#kAw#c#Wu#_#c#U}#e#y#g#WQKGGEEAWGc#Iq#EW?k#?M#g#FoBPq#J[HSDIBGB]Ja#RcAdAYX{AdAq#Ry#Hu#BU?yA#g#AYA",
},
"start_location": Object {
"lat": 52.9089381,
"lng": -1.4789711,
},
"travel_mode": "WALKING",
},
Object {
"distance": Object {
"text": "0.3 km",
"value": 272,
},
"duration": Object {
"text": "3 mins",
"value": 207,
},
"end_location": Object {
"lat": 52.9193378,
"lng": -1.4764257,
},
"html_instructions": "At the roundabout, take the <b>3rd</b> exit onto <b>Babington Ln</b>",
"maneuver": "roundabout-left",
"polyline": Object {
"points": "gl~aIju_HAIAG?CAECGACCGEEEECCEAICK?C#A#A?C#C#EDCBABCDABABCDGYgBkBwBsBw#y#GCGA",
},
"start_location": Object {
"lat": 52.9173185,
"lng": -1.4781371,
},
"travel_mode": "WALKING",
},
Object {
"distance": Object {
"text": "82 m",
"value": 82,
},
"duration": Object {
"text": "1 min",
"value": 54,
},
"end_location": Object {
"lat": 52.91985400000001,
"lng": -1.4756332,
},
"html_instructions": "Slight <b>right</b> to stay on <b>Babington Ln</b>",
"maneuver": "turn-slight-right",
"polyline": Object {
"points": "{x~aItj_HYe#cAqACCAECE?C?G#K",
},
"start_location": Object {
"lat": 52.9193378,
"lng": -1.4764257,
},
"travel_mode": "WALKING",
},
Object {
"distance": Object {
"text": "0.2 km",
"value": 217,
},
"duration": Object {
"text": "2 mins",
"value": 144,
},
"end_location": Object {
"lat": 52.9216227,
"lng": -1.4768472,
},
"html_instructions": "Turn <b>left</b> onto <b>St Peters St</b>",
"maneuver": "turn-left",
"polyline": Object {
"points": "a|~aIte_Hc#NC#gBj#MDKDaBdAq#^GHCFCFCNCFEHEF",
},
"start_location": Object {
"lat": 52.91985400000001,
"lng": -1.4756332,
},
"travel_mode": "WALKING",
},
Object {
"distance": Object {
"text": "0.3 km",
"value": 266,
},
"duration": Object {
"text": "3 mins",
"value": 186,
},
"end_location": Object {
"lat": 52.9234756,
"lng": -1.4752851,
},
"html_instructions": "Slight <b>right</b> onto <b>Corn Market</b>",
"maneuver": "turn-slight-right",
"polyline": Object {
"points": "cg_bIhm_HwCZi##MAMCIIMOSa#Yq#Oc#Qk#CEKc#EQWuA",
},
"start_location": Object {
"lat": 52.9216227,
"lng": -1.4768472,
},
"travel_mode": "WALKING",
},
Object {
"distance": Object {
"text": "0.1 km",
"value": 100,
},
"duration": Object {
"text": "1 min",
"value": 74,
},
"end_location": Object {
"lat": 52.9242042,
"lng": -1.4756769,
},
"html_instructions": "At the roundabout, take the <b>2nd</b> exit onto <b>Full St</b><div style=\"font-size:0.9em\">Destination will be on the right</div>",
"maneuver": "roundabout-left",
"polyline": Object {
"points": "wr_bIpc_HG?ICCIAKAKKFIDIFE#OPONMLa#h#?#",
},
"start_location": Object {
"lat": 52.9234756,
"lng": -1.4752851,
},
"travel_mode": "WALKING",
},
],
"travel_mode": "WALKING",
},
],
"traffic_speed_entry": Array [],
"via_waypoint": Array [],
},
],
"overview_polyline": Object {
"points": "_c{aIza`Hm#BEyHC_AyAk#uC{#OCa#JoB|#IBw#ZiBr#u#mFm#yDuE`BIDw#SI\\Q`#OR_#\\cBbAwB~#u#\\YNe#\\#??BA#?DCBE#EEAAg#RmAf#yB^IBAAAACACBA#?#e#[uGyE{DsBeBgA]IuAOcA?u#HoBPq#Jo#NQF]Ja#R}A~A{AdAq#RoBLoB#aACCQGUSWOEO#KDORCFCDGY_F_F_A}#GAYe#gAuAEW#Kc#NkBl#YJsCdBKPGVIPEFwCZw#?WMa#q#i#uAg#gBWuAG?ICCICWULOH_#`#o#x#",
},
"summary": "Normanton Rd",
"warnings": Array [
"Walking directions are in beta. Use caution – This route may be missing sidewalks or pedestrian paths.",
],
"waypoint_order": Array [],
},
],
"status": "OK",
}
I am trying to get data from transit details which has the latitudes and longitude values which i am trying to acquire to be able to view this on in the map using MapView in React native and i believe i am successful of on doing this as this is my attempt on fetching the data setting the state:
fetch('https://maps.googleapis.com/maps/api/directions/json?origin=' + latitude + ',' + longitude + '&destination=' + goingto + '&mode=transit&transit_mode=bus&key=' + apiDirectionskey)
.then((resdirections) => resdirections.json())
.then((responseJson4) => {
//const departureloc1 = responseJson4.routes[0].legs[0].steps[1];
//console.log(departureloc1)
const departureloc = responseJson4.routes[0].legs[0].steps[1].transit_details.departure_stop.location;
console.log(departureloc);
const stopmarkers = Object.keys(departureloc).map(value => {
// noinspection JSAnnotator
if (typeof departureloc['lat'] === undefined && typeof departureloc['lng'] === undefined) {
console.log('null');
} else {
return {
latlng: {
latitude: departureloc['lat'],
longitude: departureloc['lng']
}
}
}
this.setState({ departureloc: stopmarkers });
});
})
}
printing the fetch call above will result in this JSON result
Object {
"lat": 52.90736,
"lng": -1.453532,
}
The next section is my render function below which has a mapview in my attempt to set the markers.
<View style={styles.container}>
<Mainlogo/>
<TextInput style={styles.boxInput} underlineColorAndroid='rgba(0,0,0,0)' placeholder="Going To?"
underlineColorAndroid='transparent'
onChangeText={(dest) => this.setState({goingto : dest})}
/>
<TouchableOpacity style={styles.button} onPress={this.fetchDirections.bind(this)}>
<Text style={styles.textButton}> Go {this.props.type}</Text>
</TouchableOpacity>
{this.state.departureloc.map(marker => (
<MapView.Marker
coordinate={marker.latlng}
image={require('../img/busstop1.png')}
/>
))}
</MapView> : <Text style={{fontWeight: 'bold', color: '#546e7a', textAlign: 'center'}}>Please wait.. loading</Text>}
</View>
I am unsuccessful at this stage and instead i cannot get around with this error.
I am very new to this and anyone that can guide and give me pointers on the correct way would be greatly appreciated thanks
At render time, this.state.departureloc is unset, likely because render() gets called before your API calls return. Try setting this.state.departureloc = [] in your constructor(props) function.
Also it's not good to iterate within your JSX rendering. Consider extracting that rendering to before your return statement and storing it in a variable.

Splitting Json Array and groupping in to multiple messages camel

I am using Jboss fuse 6.3 and apache camel 2.17.I wanted to split a huge json message in to multiple messages in camel spring dsl.
Sample message structure is below in this message i have 9 arrays of countries i need to split in to array of two as 5 messages the last message contains only one array.The order of messages doesn't matter.
Input message:
[{
"Cities": [{
"name": "Paris",
"lat": "45.75",
"lng": "4.583333"
}, {
"name": "Marseille",
"lat": "45.97",
"lng": "4.54"
}, {
"name": "Lyon",
"lat": "24.75",
"lng": "4.75"
}, {
"name": "Toulouse",
"lat": "37.75",
"lng": "4.755"
}, {
"name": "Nice",
"lat": "89.75",
"lng": "4.77"
}],
"country": "FR"
},
{
"Cities": [{
"name": "Berlin",
"lat": "45.75",
"lng": "4.583333"
}, {
"name": "Hamburg",
"lat": "45.97",
"lng": "4.54"
}, {
"name": "Munich",
"lat": "24.75",
"lng": "4.75"
}, {
"name": "Cologne",
"lat": "37.75",
"lng": "4.755"
}, {
"name": "Frankfurt",
"lat": "89.75",
"lng": "4.77"
}],
"country": "DE"
}, {
"Cities": [{
"name": "mumbai",
"lat": "45.75",
"lng": "4.583333"
}, {
"name": "Bangalore",
"lat": "45.97",
"lng": "4.54"
}, {
"name": "Delhi",
"lat": "24.75",
"lng": "4.75"
}, {
"name": "Chattisgarh",
"lat": "37.75",
"lng": "4.755"
}, {
"name": "Hyderabad",
"lat": "89.75",
"lng": "4.77"
}],
"country": "IN"
}, {
"Cities": [{
"name": "Aberdeen",
"lat": "45.75",
"lng": "4.583333"
}, {
"name": "Armagh",
"lat": "45.97",
"lng": "4.54"
}, {
"name": "Bangor",
"lat": "24.75",
"lng": "4.75"
}, {
"name": "Bath",
"lat": "37.75",
"lng": "4.755"
}, {
"name": "Belfast",
"lat": "89.75",
"lng": "4.77"
}],
"country": "UK"
}, {
"Cities": [{
"name": "Budapest",
"lat": "45.75",
"lng": "4.583333"
}, {
"name": "Debrecen",
"lat": "45.97",
"lng": "4.54"
}, {
"name": "Szeged",
"lat": "24.75",
"lng": "4.75"
}, {
"name": "Miskolc",
"lat": "37.75",
"lng": "4.755"
}, {
"name": "Pecs",
"lat": "89.75",
"lng": "4.77"
}],
"country": "HUNGARY"
}, {
"Cities": [{
"name": "Alingsas",
"lat": "45.75",
"lng": "4.583333"
}, {
"name": "Arboga",
"lat": "45.97",
"lng": "4.54"
}, {
"name": "Arvika",
"lat": "24.75",
"lng": "4.75"
}, {
"name": "Askersund",
"lat": "37.75",
"lng": "4.755"
}, {
"name": "Avesta",
"lat": "89.75",
"lng": "4.77"
}],
"country": "SWEDEN"
}, {
"Cities": [{
"name": "Amsterdam",
"lat": "45.75",
"lng": "4.583333"
}, {
"name": "Den Helder",
"lat": "45.97",
"lng": "4.54"
}, {
"name": "Edam",
"lat": "24.75",
"lng": "4.75"
}, {
"name": "Haarlem",
"lat": "37.75",
"lng": "4.755"
}, {
"name": "Purmerend",
"lat": "89.75",
"lng": "4.77"
}],
"country": "NETHERLANDS"
}, {
"Cities": [{
"name": "Abrantes",
"lat": "45.75",
"lng": "4.583333"
}, {
"name": "Agualva-Cacem",
"lat": "45.97",
"lng": "4.54"
}, {
"name": "Agueda",
"lat": "24.75",
"lng": "4.75"
}, {
"name": "Albufeira",
"lat": "37.75",
"lng": "4.755"
}, {
"name": "Alcacer do Sal",
"lat": "89.75",
"lng": "4.77"
}],
"country": "PORTUGAL"
}, {
"Cities": [{
"name": "Barcelona",
"lat": "45.75",
"lng": "4.583333"
}, {
"name": "madrid",
"lat": "45.97",
"lng": "4.54"
}, {
"name": "Saragossa",
"lat": "24.75",
"lng": "4.75"
}, {
"name": "Salamanca",
"lat": "37.75",
"lng": "4.755"
}, {
"name": "Granada",
"lat": "89.75",
"lng": "4.77"
}],
"country": "SPAIN"
}
]
Expected output:
First split:
[{
"Cities": [{
"name": "Paris",
"lat": "45.75",
"lng": "4.583333"
}, {
"name": "Marseille",
"lat": "45.97",
"lng": "4.54"
}, {
"name": "Lyon",
"lat": "24.75",
"lng": "4.75"
}, {
"name": "Toulouse",
"lat": "37.75",
"lng": "4.755"
}, {
"name": "Nice",
"lat": "89.75",
"lng": "4.77"
}],
"country": "FR"
},
{
"Cities": [{
"name": "Berlin",
"lat": "45.75",
"lng": "4.583333"
}, {
"name": "Hamburg",
"lat": "45.97",
"lng": "4.54"
}, {
"name": "Munich",
"lat": "24.75",
"lng": "4.75"
}, {
"name": "Cologne",
"lat": "37.75",
"lng": "4.755"
}, {
"name": "Frankfurt",
"lat": "89.75",
"lng": "4.77"
}],
"country": "DE"
}
]
Second split:
[{
"Cities": [{
"name": "mumbai",
"lat": "45.75",
"lng": "4.583333"
}, {
"name": "Bangalore",
"lat": "45.97",
"lng": "4.54"
}, {
"name": "Delhi",
"lat": "24.75",
"lng": "4.75"
}, {
"name": "Chattisgarh",
"lat": "37.75",
"lng": "4.755"
}, {
"name": "Hyderabad",
"lat": "89.75",
"lng": "4.77"
}],
"country": "IN"
},{
"Cities": [{
"name": "Aberdeen",
"lat": "45.75",
"lng": "4.583333"
}, {
"name": "Armagh",
"lat": "45.97",
"lng": "4.54"
}, {
"name": "Bangor",
"lat": "24.75",
"lng": "4.75"
}, {
"name": "Bath",
"lat": "37.75",
"lng": "4.755"
}, {
"name": "Belfast",
"lat": "89.75",
"lng": "4.77"
}],
"country": "UK"
}
]
.
.
.
Fifth split:
[{
"Cities": [{
"name": "Barcelona",
"lat": "45.75",
"lng": "4.583333"
}, {
"name": "madrid",
"lat": "45.97",
"lng": "4.54"
}, {
"name": "Saragossa",
"lat": "24.75",
"lng": "4.75"
}, {
"name": "Salamanca",
"lat": "37.75",
"lng": "4.755"
}, {
"name": "Granada",
"lat": "89.75",
"lng": "4.77"
}],
"country": "SPAIN"
}
]
I tried below referring Apache Camel with Json Array split from the post of Ricardo.But iam not sure how to configure aggregate(AggregationStrategies.groupedExchange()) in spring dsl.
Camel route:
<split streaming="true">
<jsonpath>$</jsonpath>
<aggregate completionTimeout="1000" completionSize="2" groupExchanges="true">
</aggregate>
<log message="${body}"></log>
</split>
Here's a simple example of how you could split your JSON array using Spring DSL:
<split>
<jsonpath>$</jsonpath>
<!-- Add rest of the logic here -->
</split>
The Spring DSL example from the mentioned question is this one:
<camel:route>
<camel:from uri="direct:start" />
<camel:split streaming="true">
<camel:jsonpath>$</camel:jsonpath>
<camel:aggregate completionSize="5"
completionTimeout="1000" groupExchanges="true">
<camel:correlationExpression>
<camel:constant>true</camel:constant>
</camel:correlationExpression>
<camel:log message="${body}"></camel:log>
<camel:to uri="mock:result"></camel:to>
</camel:aggregate>
</camel:split>
</camel:route>
There's a full implementation example here.
The groupExchange property just return a default aggregation strategy: GroupedExchangeAggregationStrategy.
You could implement your own and pass it as a bean parameter to your DSL like this:
<camel:route>
<camel:from uri="direct:start" />
<camel:split streaming="true">
<camel:jsonpath>$</camel:jsonpath>
<camel:aggregate strategyRef="stringConcatStrategy" completionSize="5"
completionTimeout="1000" >
<camel:correlationExpression>
<camel:constant>true</camel:constant>
</camel:correlationExpression>
<camel:log message="${body}"></camel:log>
<camel:to uri="mock:result"></camel:to>
</camel:aggregate>
</camel:split>
</camel:route>
Cheers!

Export Google map directions to lat/long

I have multiple sets of lat/long coordinates that I am using in the Google directions API with way points to get directions following roads and paths. Each set of coordinates have about 100 points which I am converting to a usable number for the start, end and waypoints.
I would like to get the lat/long values from the directions which are returned from Google. Basically get each coordinate from each road segment.
Is this possible?
Yes, by using the direction API, you would get a respond like this:
{
"status": "OK",
"geocoded_waypoints" : [
{
"geocoder_status" : "OK",
"place_id" : "ChIJ7cv00DwsDogRAMDACa2m4K8",
"types" : [ "locality", "political" ]
},
{
"geocoder_status" : "OK",
"place_id" : "ChIJ69Pk6jdlyIcRDqM1KDY3Fpg",
"types" : [ "locality", "political" ]
},
{
"geocoder_status" : "OK",
"place_id" : "ChIJgdL4flSKrYcRnTpP0XQSojM",
"types" : [ "locality", "political" ]
},
{
"geocoder_status" : "OK",
"place_id" : "ChIJE9on3F3HwoAR9AhGJW_fL-I",
"types" : [ "locality", "political" ]
}
],
"routes": [ {
"summary": "I-40 W",
"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"
}
},
...
... additional steps of this leg
...
... additional legs of this route
"duration": {
"value": 74384,
"text": "20 hours 40 mins"
},
"distance": {
"value": 2137146,
"text": "1,328 mi"
},
"start_location": {
"lat": 35.4675602,
"lng": -97.5164276
},
"end_location": {
"lat": 34.0522342,
"lng": -118.2436849
},
"start_address": "Oklahoma City, OK, USA",
"end_address": "Los Angeles, CA, USA"
} ],
"copyrights": "Map data ©2010 Google, Sanborn",
"overview_polyline": {
"points": "a~l~Fjk~uOnzh#vlbBtc~#tsE`vnApw{A`dw#~w\\|tNtqf#l{Yd_Fblh#rxo#b}#xxSfytAblk#xxaBeJxlcBb~t#zbh#jc|Bx}C`rv#rw|#rlhA~dVzeo#vrSnc}Axf]fjz#xfFbw~#dz{A~d{A|zOxbrBbdUvpo#`cFp~xBc`Hk#nurDznmFfwMbwz#bbl#lq~#loPpxq#bw_#v|{CbtY~jGqeMb{iF|n\\~mbDzeVh_Wr|Efc\\x`Ij{kE}mAb~uF{cNd}xBjp]fulBiwJpgg#|kHntyArpb#bijCk_Kv~eGyqTj_|#`uV`k|DcsNdwxAott#r}q#_gc#nu`CnvHx`k#dse#j|p#zpiAp|gEicy#`omFvaErfo#igQxnlApqGze~AsyRzrjAb__#ftyB}pIlo_BflmA~yQftNboWzoAlzp#mz`#|}_#fda#jakEitAn{fB_a]lexClshBtmqAdmY_hLxiZd~XtaBndgC"
},
"warnings": [ ],
"waypoint_order": [ 0, 1 ],
"bounds": {
"southwest": {
"lat": 34.0523600,
"lng": -118.2435600
},
"northeast": {
"lat": 41.8781100,
"lng": -87.6297900
}
}
} ]
}
Where you can get the lat/lng of each turning points under steps. You can even decode the polyline to get the set of points which describe the road.