Skip to content
sdpatro edited this page Jul 16, 2015 · 3 revisions

#Locations

The locations module currently provides the following set of features:

  1. An offline brochure of all the places in NSIT.
  2. Map view of a location using Google Maps API v3.
  3. Current distance to the location and time required to reach by driving and walking, using Google Directions API.

The offline brochure is implemented using a LocationsGroup and Locations structure. The Locations Group class is defined below:

    class LocationGroup{
        String GroupHeader;
        String GroupType;
        ArrayList<Location> Locations;

        LocationGroup(String GroupHeader, String GroupType, ArrayList<Location> Locations){
            this.GroupHeader = GroupHeader;
            this.GroupType = GroupType;
            this.Locations = Locations;
        }
    }

It uses a GroupHeader to name the heading of the locations group, a GroupType to specify the type (for assigning the icon in the list), and an array list of all the locations that come under the group.

Location class is defined as:

    class Location{
        String Name;
        LatLng Coord;

        public Location(String Name, LatLng Coord) {
            this.Name = Name;
            this.Coord = Coord;
        }
    }

It has a name, and coordinates in latitude-longitude format for passing it to map view class to render it in the map.

The offline brochure is populated using:

    public void FillGroupsList(){
        *// All information is hard-coded here*
    }

The information passed to LocationsMapView is done via the list adapter for the ExpandableListView.

The LocationsMapView class renders the marker of the location on the map using the parameters passed in the intent.

To get the directions related stuff, the following code is responsible:

    ...
        protected String doInBackground(String... Coordinates) {
            try {
                ...
                HttpUriRequest request = new HttpGet("https://maps.googleapis.com/maps/api/directions/json?origin="+OriginLat+","+OriginLong+"&destination="+DestinationLat+","+DestinationLong+"&key=AIzaSyBgktirlOODUO9zWD-808D7zycmP7smp-Y&mode=driving");
                ResponseHandler<String> responseHandler = new BasicResponseHandler();
                String DriveResult = client.execute(request, responseHandler);
                Log.e("URL","https://maps.googleapis.com/maps/api/directions/json?origin="+OriginLat+","+OriginLong+"&destination="+DestinationLat+","+DestinationLong+"&key=AIzaSyBgktirlOODUO9zWD-808D7zycmP7smp-Y&mode=driving");
                request = new HttpGet("https://maps.googleapis.com/maps/api/directions/json?origin="+OriginLat+","+OriginLong+"&destination="+DestinationLat+","+DestinationLong+"&key=AIzaSyBgktirlOODUO9zWD-808D7zycmP7smp-Y&mode=walking");
                String WalkResult = client.execute(request, responseHandler);

                return DriveResult+"/NSITAPP/"+WalkResult;
            } catch (Exception e) {
                ...
            }
        }
    ...

As you can see, the information is obtained using the GET request done to https://maps.googleapis.com/maps/api/directions/.

For any sort of questions/doubts you have regarding the documentation, please contact Swati Garg at swati4star@gmail.com.

Clone this wiki locally