0

I have an Android application and I'm trying to populate a Google Map with a route, this route is store on a JSON array this way:

JSONArray.getString("points") = ["-33.45591917507404, -70.59198361376951","-33.453484420618416, -70.61635952929686"]

So in this case I have

Point A=(-33.49088437162095, -70.64043194102163) and

Point B=(-33.49423964397045, -70.63992768572683)

And my route or path is A-----B

I'm new to Android and I was wondering how to get this to work. Also, in this case my route is A-----B, but it can also be A----B----C----D. I can have any number of points on the path.

Peter O.
  • 32,158
  • 14
  • 82
  • 96
leonardo
  • 41
  • 1
  • 8
  • You can see so many related question with yours. [Here](http://stackoverflow.com/q/2023669/1050058) is best solution IMO. Remember search before asking. – Trung Nguyen Oct 24 '12 at 03:09

1 Answers1

1

One thing you can try is the Google Maps Polyline object: https://developers.google.com/maps/documentation/javascript/reference#Polyline You specify to setPath() an ordered list of the points (either an Array of LatLng or an MVCArray or LatLng), you want to connect together on the map, and Google Maps will make a polyline for you to your specifications.

// path = Array of LatLng or MVCArray of LatLng
routeLine = new Polyline();
routeLine.setPath(JSONArray);

In your case, passing JSONArray into setPath should work OK.

If you want to get fancy and incorporate directions, you need to use the Google Directions API. https://developers.google.com/maps/documentation/javascript/directions

// All waypoints must be stopovers for the Directions service to optimize their route.
// start & end are of type String or LatLng, waypts is an array of String or LatLng
request = {
    origin: start,
    destination: end,
    waypoints: waypts,
    optimizeWaypoints: [type Boolean],
    travelMode: [type TravelMode]
};
// go on and actually perform the request
directionsService.route(request, function(result, status) {
    if (status == google.maps.DirectionsStatus.OK) {
        // if successful, this will run
    }
});

Once you finish constructing your object, you should be able to display it by running setMap(map:Map), such as

routeLine.setMap(map)
Stephen Wylie
  • 924
  • 7
  • 10
  • Oh well, this is for JavaScript, not quite for Android. You could always embed a Google Map into a WebView if you don't find out how to do it in native Android... – Stephen Wylie Oct 24 '12 at 03:03