Created
June 1, 2017 17:11
-
-
Save tugrulcan/815f1ede783ce1427b0b721e4a1a2da9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getRoute = () => { | |
let addressDict = new Map(); | |
for (student of sampleData.studentList) { | |
addressDict.set(student.studentID, student.address); | |
} | |
let wpoints_array = Array.from(addressDict.values()); | |
let wpoints_query = ""; | |
for (wp of wpoints_array) { | |
wpoints_query += wp + "|"; | |
} | |
wpoints_query = wpoints_query.substring(0, wpoints_query.length - 1); | |
let origin_coords = this.state.longitude.toString() + ',' + this.state.latitude.toString(); | |
let destination = 'Muradiye Mah. Manolya Sokak No:234 Yunusemre - Manisa'; | |
let q_url = "https://maps.googleapis.com/maps/api/directions/json?origin=" + origin_coords; | |
q_url += "&destination=" + destination; | |
q_url += "&waypoints=" + wpoints_query; | |
q_url += "&optimizeWaypoints=true"; | |
q_url += "&travelMode=DRIVING"; | |
q_url += "&key=AIzaSyCOqYI7eM7halH9qb10BmTGbrtrqfgBUw4"; | |
console.log("q_url: " + encodeURI(q_url)); | |
fetch(encodeURI(q_url)) | |
.then(function (response) { | |
return response.json(); | |
}) | |
.then((response) => { | |
console.log("responsejson: " + JSON.stringify(response)); | |
//alert("responseJson: " + JSON.stringify(responseJson)); | |
let url = 'http://maps.google.com/maps?saddr=' + origin_coords; | |
for (let index = 0; index < response.routes[0].waypoint_order.length; index++) { | |
let element = response.routes[0].waypoint_order[index]; | |
let addr = wpoints_array[element]; | |
if (index === 0) | |
url += "&daddr=" + addr; | |
else | |
url += "+to:" + addr; | |
} | |
url += "+to:Muradiye Mah. Manolya Sokak No:234 Yunusemre - Manisa&dirflg=d"; | |
console.log("url : " + encodeURI(url)); | |
Linking.openURL(encodeURI(url)); | |
}); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example q_url:
https://maps.googleapis.com/maps/api/directions/json?origin=38.43882333333333,27.202935000000004&destination=Muradiye%20Mah.%20Manolya%20Sokak%20No:234%20Yunusemre%20-%20Manisa&waypoints=1901.%20Sk.%20No:43,%20Saruhan%20Mahallesi,%2045010%20Manisa%20Merkez/Manisa,%20Türkiye|Oktay%20Erol%20Pulcuoğlu%20Cd.%20No:8,%2045030%20Keçiliköy%20Osb/Manisa%20Merkez/Manisa,%20Türkiye|Manisa%20TOKİ%20Konutları%20No:3,%20Uncubozköy%20Mahallesi,%2045030%20Manisa%20Merkez/Manisa,%20Türkiye|5619.%20Sk.%20No:2,%20Keçili%20Köy%20Mahallesi,%2045030%20Manisa%20Merkez/Manisa,%20Türkiye|Vali%20Azizbey%20Cd.%20No:34,%2075.%20Yıl%20Mahallesi,%2045030%20Manisa%20Merkez/Manisa,%20Türkiye|43.%20Sk.%20No:23,%20Turgut%20Özal%20Mahallesi,%2045040%20Manisa%20Merkez/Manisa,%20Türkiye|308.%20Sk.%20No:130,%20Kazım%20Karabekir%20Mahallesi,%2045040%20Şehzadeler/Manisa,%20Türkiye|1803.%20Sk.%20No:7,%20Çarşı%20Mahallesi,%2045010%20Manisa%20Merkez/Manisa,%20Türkiye&optimizeWaypoints=true&travelMode=DRIVING&key=AIzaSyCOqYI7eM7halH9qb10BmTGbrtrqfgBUw4