I've gt this map route to work on iOS. Now i want to do it on android. What are the steps needed to make it work on android?
This is the code that works on iOS:
var route = { name: 'Exercise Route', color: "#00f", width: 2 }; var annotation = [Ti.Map.createAnnotation({ latitude:mapData[0].latitude, longitude:mapData[0].longitude, title:'Test', subtitle:contactDataUp[0].address, animate:true, rightButton:'/Images/startbutton.png', //pincolor: Ti.Map.ANNOTATION_RED image:pinImage })]; var mapView = Titanium.Map.createView({ top:0, width:screenWidth, height:innerViewHeight, mapType: Ti.Map.STANDARD_TYPE, region:{ latitude:mapData[0].latitude, longitude:mapData[0].longitude, latitudeDelta:0.0035, longitudeDelta:0.0035 }, animate:true, regionFit:true, userLocation:true, annotations: annotation }); innerView.add(mapView); var points = []; var current = {}; mapView.addEventListener('click', function(e){ Ti.API.warn('click'); if(e.clicksource ==='rightButton'){ //Ti.API.warn(e); Ti.API.warn('clicked'); mapView.removeRoute(route); points = []; points.push({latitude:e.annotation.latitude, longitude:e.annotation.longitude}); //readRoute(points); Ti.Geolocation.distanceFilter = 10; Ti.Geolocation.purpose = "To obtain user location for tracking distance travelled"; Ti.Geolocation.getCurrentPosition(function(evt) { var origin = String(evt.coords.latitude + ',' + evt.coords.longitude), travelMode = 'walking', destination = String(points[0].latitude + ',' + points[0].longitude), url = "http://maps.google.com/maps/api/directions/xml?mode=" + travelMode + "&origin=" + origin + "&destination=" + destination +"&sensor=false"; xhr = Titanium.Network.createHTTPClient(); xhr.open('GET',url); Ti.API.info('>>> go get data for Rgeocode! ...URL: ' + url); xhr.onerror = function(e){ alert('No possible route'); //Ti.App.fireEvent('app:hide indicator'); } xhr.onload = function(e){ var xml = this.responseXML, points = [], steps = xml.documentElement.getElementsByTagName("step"), totalSteps = steps.length; for(var i = 0; i < totalSteps; i++) { var polylineString = steps.item(i).getElementsByTagName("polyline").item(0).getElementsByTagName("points").item(0).text, decodedPolyline = decodeLine(polylineString); for (var j = 0; j < decodedPolyline.length; j++) { if (decodedPolyline[j] != null) { points.push({ latitude : decodedPolyline[j][0], longitude : decodedPolyline[j][1] }); } } } // Get last point and add it to the array, as we are only parsing <start_location> var finalLocation = steps.item(totalSteps - 1).getElementsByTagName("end_location"), finalLatitude = finalLocation.item(0).getElementsByTagName("lat").item(0).text, finalLongitude = finalLocation.item(0).getElementsByTagName("lng").item(0).text; points.push({latitude:finalLatitude, longitude:finalLongitude}); // Create route and annotations var route = { name:"bonVoyage", points:points, color:"blue", width:6 }, startAnnotation = Ti.Map.createAnnotation({ pincolor: Ti.Map.ANNOTATION_RED, latitude: points[0].latitude, longitude: points[0].longitude, title: 'Current location' }), endAnnotation = Ti.Map.createAnnotation({ pincolor: Ti.Map.ANNOTATION_RED, latitude: points[points.length - 1].latitude, longitude: points[points.length - 1].longitude, title: 'Destination' }); // Add elements mapView.addRoute(route); mapView.addAnnotation(startAnnotation); mapView.addAnnotation(endAnnotation); }; xhr.send(); }); } });will the same work on android?
2 Answers
hi,
i think this should be work in android too.....
there's a great free module on the market: Google Directions . I use it in one of my apps and it's great. It works on either ios and android
Your Answer
Think you can help? Login to answer this question!