Skip to content

Instantly share code, notes, and snippets.

@claraj
Created May 12, 2016 21:22
Show Gist options
  • Save claraj/fc17756404d7793f936e172ddc7fe9df to your computer and use it in GitHub Desktop.
Save claraj/fc17756404d7793f936e172ddc7fe9df to your computer and use it in GitHub Desktop.
package com.company;
import com.google.maps.DirectionsApi;
import com.google.maps.GeoApiContext;
import com.google.maps.model.DirectionsLeg;
import com.google.maps.model.DirectionsRoute;
import com.google.maps.model.DirectionsStep;
import java.util.ArrayList;
/**
* Created by admin on 12/6/15.
*/
class schoolroute {
public String school1;
public String school2;
public
String dist;
schoolroute(String s1, String s2, String d) {
school1 = s1;
school2 = s2;
dist = d;
}
@Override
public boolean equals(Object otherSchool){
if (otherSchool instanceof schoolroute) {
schoolroute other = (schoolroute)otherSchool;
if (this.school1.equals(this.school2) && this.school2.equals(other.school1)) {
return true;
}
if (this.school1.equals(this.school1) && this.school2.equals(other.school2)) {
return true;
}
}
return false;
}
@Override
public String toString(){
return "Distance from " + school1 + " to " + school2 + " is " + dist;
}
}
public class SchoolDistances {
public static void main(String args[]) {
String[] schools = {
"Andersen Elementary School, 1098 Andersen Ln, Minneapolis, MN 55407",
"Anthony Middle School, 5757 Irving Avenue South, Minneapolis, MN 55419",
"Bethune Community School, 919 Emerson Avenue North, Minneapolis, MN 55411",
"Cedar Island Elementary School, 6777 Hemlock Lane North, Maple Grove, MN 55369",
"Robbinsdale Cooper High School, 8230 47th Avenue North, New Hope, MN 55428",
"Dowling Elementary School, 3900 West River Parkway, Minneapolis, MN 55406",
"Edinbrook Elementary School, 8925 Zane Avenue North, Brooklyn Park, MN 55443",
"Edison High School, 700 22nd Avenue Northeast, Minneapolis, MN 55418",
"Fernbrook Elementary School, 9661 Fernbrook Ln N, Maple Grove, MN 55369",
"Folwell School - Performing Arts Magnet, 3611 20th Avenue South, Minneapolis, MN 55407",
"Franklin Middle School, 1501 Aldrich Avenue North, Minneapolis, MN 55411",
"Head Start-Parents-Community, 700 Humboldt Avenue North, Minneapolis, MN 55411", //"fraser head start"
"Patrick Henry High School, 4320 Newton Ave N, Minneapolis, MN 55412",
"Jefferson Elementary School, 1200 West 26th Street, Minneapolis, MN 55405",
"Keewaydin Elementary School, 5209 30th Avenue South, Minneapolis, MN 55417",
"Lake Harriet Lower Elementary School, 4030 Chowen Avenue South, Minneapolis, MN 55410",
"Lake Harriet Upper Elementary School, 4912 Vincent Avenue South, Minneapolis, MN 55410",
"Learning for Leadership Charter School, 3300 5th Street Northeast # 150, Minneapolis, MN 55418", //"Learning 4LDSHP",
"McKnight Early Childhood Family Development Center, 4225 3rd Avenue South, Minneapolis, MN 55409",
"Minneapolis Early Childhood Special Education, 3328 Elliot Avenue South, Minneapolis, MN 55407",
"North Community High School, 1500 James Avenue North, Minneapolis, MN 55411",
"Parents In Community Action, 8500 Zane Avenue North, Brooklyn Park, MN 55443",
"Osseo Senior High School, 317 2nd Avenue Northwest, Osseo, MN 55369",
"Parnassus Preparatory School, 11201 96th Avenue North, Maple Grove, MN 55369",
"Pillsbury Elementary School, 2250 Garfield St NE, Minneapolis, MN 55418",
"Ramsey Middle School, West 49th Street, Minneapolis, MN",
"Rice Lake Elementary School, 13755 89th Avenue North, Maple Grove, MN 55369",
"Sanford Middle School, 42nd Avenue South, Minneapolis, MN",
"South High School, South 19th Avenue, Minneapolis, MN",
"Anne Sullivan Communication Center, 3100 East 28th Street, Minneapolis, MN 55406",
"North Education Center, 5530 Zealand Ave North, New Hope, MN 55428 ",
"Transition Plus, 3320 Elliot Avenue South Minneapolis, MN 55407",
"Twin Cities International Elementary School, 277 N 12th Ave, Minneapolis, MN 55401, United States",
"Waite Park Elementary School, 1800 34th Avenue Northeast, Minneapolis, MN 55418",
"Washburn High School, 201 West 49th Street, Minneapolis, MN 55419",
"Webster Elementary, 425 5th Street Northeast, Minneapolis, MN 55413",
"Woodland Elementary School, 4501 Oak Grove Parkway, Minneapolis, MN 55443"
};
// String[] schools = { "South High School, Minneapolis" , "Washburn High School Minneapolis", "Ramsey Middle School, Minneapolis"};
String distances = "";
GeoApiContext context = new GeoApiContext();
String key = "YOUR KEY GOES HERE"; //todo
context.setApiKey(key);
ArrayList<schoolroute> allRoutes = new ArrayList<schoolroute>();
for (int s = 0; s < schools.length; s++) {
for (int t = 0; t < schools.length; t++) {
if (s == t) { continue; }
String origin = schools[s];
String destination = schools[t];
System.out.println("testing" + origin + " " + destination);
try {
schoolroute rt = new schoolroute(origin, destination, null);
boolean exists = false;
for (schoolroute route : allRoutes) {
if (rt.equals(route)) {
System.out.println(route + " equals " + rt);
exists = true;
break; }
}
if (!exists) {
DirectionsRoute[] routes = DirectionsApi.getDirections(context, origin, destination).await();
for (DirectionsRoute r : routes) {
for (DirectionsLeg leg : r.legs) {
rt.dist = leg.distance.toString();
allRoutes.add(rt);
String distance = "Distance from " + origin + " to " + destination + " is " + leg.distance;
System.out.println(rt);
distances = distances + rt + "\n";
}
}
}
} catch (Exception e) {
System.out.println(e);
}
}
}
System.out.println("all distances:");
System.out.println(distances);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment