I used setpage and did a replaceAll on your hardcoded places, I then went on to do the same for waypoints, I may as well post it here, its not going to be pruned perfectly for the forum but what the hell, this is a new field and we are here to help, so pick through some of the bad bits folks. But basically I got the way points going and everything, im so super in love with this "webview" approach, did you even realise it supports street view natively too? Perhaps you did but when I noticed I almost shat myself with joy, you click on the man, he tilts, you drag him somewhere and bang, streetview!!! My clients are going to love me :-))).. Thanks, the JS bridge kicks ass, its brought so much stuff with it. Oh yeh I also worked out 2 other AMAZING things, clearly from googles madness, but if you tap and hold your finger somewhere it will show you a screenshot of the street view ! Too good to be true, and if you do some trickery you can include your own custom little map pins using code from:
Anyway here is some code I hope will prove useful to someone who is trying to take shannah's demo and a) programatically adjust the start/end, b) add way points into the map, I replace the existing onLoad() with:
@Override
public void onLoad(String url) {
_("/////////////////BROWSER HAS FINISHED LOADING//////////// Loaded "+url);
/*
when the browser loads the javascript creates these objects which we grab so the directions
* can be displayed
*/
map = (JSObject)c.get("map");
directionsService = (JSObject)c.get("directionsService");
directionsDisplay = (JSObject)c.get("directionsDisplay");
if (directionsService==null)
{
_("WARNING directionsService IS STILL NULL!!! ");
}
if (directionsDisplay==null)
{
_("WARNING directionsDisplay IS STILL NULL!!! ");
}
GoogleMap.this.onLoad();
}
};
browser = (BrowserComponent)b.getInternal();
c = new JavascriptContext(browser);
boolean SUPPLY_HTML_AS_STRING=true;
if (SUPPLY_HTML_AS_STRING)
{
String htmlContent = "";
InputStream is = Display.getInstance().getResourceAsStream(Form.class,"/googlemaps.html");
try {
htmlContent = Util.readToString(is);
} catch (IOException ex) {
_("IOEXCEPTION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! "+ex.getMessage());
}
_("html was loaded into a string and looks like this:");
//_(""+htmlContent);
//now we swap into the html the real values not the hardcoded ones...
String originToReplace = "Junee, Australia";
String destinationToReplace = "Sydney Australia";
//we also need to work out the center point to tell the map where to focus..
//or do we? well to specify the extra things we do, inside the js theres a line like this:
/*
var map = new google.maps.Map(document.getElementById('map'), {
center: new google.maps.LatLng(-34.397, 150.644),
zoom:7,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
*
* So for now lets swap:
*/
//center: new google.maps.LatLng(-34.397, 150.644), FOR NOTHING.. later we can calc the real centre?
//THE reason i remove this is because if you dont it sort of centres then refreshes to draw the line, this way (without it)
//it will not draw til the route is ready - OR ATLEAST THATS HOW IT SEEMS ON THE SIMULATOR this might need to be
//tweaked later.
String centerString = "center: new google.maps.LatLng(-34.397, 150.644),";
htmlContent = StringUtil.replaceAll(htmlContent, centerString,"");//
htmlContent = StringUtil.replaceAll(htmlContent, originToReplace, nl.myCurrentTrip.tripPlanner_StartPoint);
htmlContent = StringUtil.replaceAll(htmlContent, destinationToReplace, nl.myCurrentTrip.tripPlanner_EndPoint);
//NOW to process way points, we need to replace the hardcoded array which ive copied from another example, it looks like:
/*
* var waypts = [
{location:"Rue de la Brigade alsace-Lorraine, Strasbourg"},
{location:"Place d'Austerlitz, Strasbourg"},
{location:"Rue des Orphelins, Strasbourg"},
{location:"Place de Zurich, Strasbourg"},
{location:"3 Rue de Zurich, Strasbourg"},
{location:"Quai des bateliers, Strasbourg"},
{location:"18 Rue du Vieux marché aux Poissons, Strasbourg"},
{location:"65 Rue des Grandes Arcades, Strasbourg"},
];
*
* BUT IVE REMOVED THEM ALL SO WE MANUALLY ADD THEM IF NEEDED.
*/
//so for now its:
String removeMe = "var waypts = [\n" +
" {location:\"Rue de la Brigade alsace-Lorraine, Strasbourg\"}\n" +
" ];";
String newWayPointJS = "var waypts = [";
//PERHAPS I NEED TO KEEP A LIST OF STOPS IN THE TRIP OBJECT RATHER THAN THIS, revisit this code if need be
if (nl.myCurrentTrip.tripPlanner_Stops !=null && nl.myCurrentTrip.tripPlanner_Stops.length()>0)
{
_("This joiurney DOES HAVE way points lets add them now!");
String listOfWayPoints = nl.myCurrentTrip.tripPlanner_Stops;
//HMM REMOVE OPTIMIZE STRING FOR NOW, work out if we need later and where to add..
if (listOfWayPoints.indexOf("optimize:true")!=-1)
{
_("removing optimize:true");
//chop off from first | to end.
listOfWayPoints = listOfWayPoints.substring(listOfWayPoints.indexOf("|")+1, listOfWayPoints.length());
_("new way point string to slot into JS:"+listOfWayPoints);
}
else
{
_("optimize:true isnt found so no need to remove it.");
}
StringTokenizer st = new StringTokenizer(listOfWayPoints,"|");
while (st.hasMoreElements())
{
String myToken = (String) st.nextElement();
_("TOKEN FOUND:"+myToken);
newWayPointJS+="{location:\""+myToken+"\"},";
}
//remove last comma then
newWayPointJS = newWayPointJS.substring(0,newWayPointJS.length()-1);
//add the end of the JS array of waypoints
newWayPointJS += " ];";
//this ocmpletes our new waypoint code that we now swap in for the hardcoded stuff
htmlContent = StringUtil.replaceAll(htmlContent, removeMe,newWayPointJS);//
}
else
{
_("There wil be NO WAY POINTS.");
//remove the way point code altogether
htmlContent = StringUtil.replaceAll(htmlContent, removeMe,"");//
}
_("===========================================================================================");
_("HTML WAS PROCESSED TO SHOW CORRECT DATA ITS NOW:");
_(""+htmlContent);
_("now pass it to the browser");
}
else
{
//now we load our own html file, (warnign this one is hardcoded in the html, hence why were are not using it in this manner right now)