<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="0Qnjnnx4kebwXWubnCMTZFF8ODK-v30euGnyIfw"
>
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
/>
<ProgressBar android:id="@+id/ProgressBar" android:layout_centerInParent="true"
android:layout_width="wrap_content" android:layout_height="wrap_content"
style="?android:attr/progressBarStyleLarge"
android:visibility="gone"/>
</LinearLayout>
package com.shifa.latihan1;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import org.json.JSONException;
import org.json.JSONObject;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.database.Cursor;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Toast;
public class SHC extends Activity {
private WebView mWebView;
String myCity="Posisi Anda",myLati="-6.353416,",myLongi="106.832510";
String myCity2="Posisi Anda",myLati2="-6.353416,",myLongi2="106.832510";
LocationManager myLocationManager=null;
ProgressDialog dialog = null;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.refresh, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.refresh:
if (!myLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
createGpsDisabledAlert();
}else{
getLocation();
}
return true;
case R.id.OfflineMode:
startActivity(new Intent (this, SHC.class));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.SHC);
Intent io = this.getIntent();
myLati=io.getStringExtra("myLati");
myLongi=io.getStringExtra("myLongi");
myCity=io.getStringExtra("myPosisi");
myLati2=io.getStringExtra("latitude");
myLongi2=io.getStringExtra("longitude");
myCity2=io.getStringExtra("tujuan");
dialog=new ProgressDialog(this);
mWebView = (WebView) findViewById(R.id.webview);
myLocationManager=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
if (!myLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
createGpsDisabledAlert();
} else{
getLocation();
}
}
@Override
public void onResume() {
super.onResume();
}
@Override
public void onPause() {
super.onPause();
}
@Override
public void onStop() {
super.onPause();
remove();
}
public void remove() {
myLocationManager.removeUpdates(onLocation);
}
LocationListener onLocation = new LocationListener() {
public void onLocationChanged(Location location) {
if (location != null) {
Toast.makeText(getBaseContext(), "Take Of Map..", Toast.LENGTH_SHORT).show();
StringBuilder buf=new StringBuilder("javascript:loadAtStart(");
buf.append(String.valueOf(location.getLatitude()));
buf.append(",");
buf.append(String.valueOf(location.getLongitude()));
buf.append(",13)");
mWebView.loadUrl(buf.toString());
remove();
Toast.makeText(getBaseContext(), "Lokasi didapatkan", Toast.LENGTH_SHORT).show();
}
}
public void onProviderDisabled(String provider) {
}
public void onProviderEnabled(String provider) {
// required for interface, not used
}
public void onStatusChanged(String provider, int status,Bundle extras) {
// required for interface, not used
}
};
private void createGpsDisabledAlert(){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("GPS tidak aktif. Aktifkan sekarang?")
.setCancelable(false)
.setPositiveButton("Aktifkan GPS",new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int id){
showGpsOptions();
getLocation();
}
});
builder.setNegativeButton("Batalkan",
new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int id){
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
private void showGpsOptions(){
Intent gpsOptionsIntent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(gpsOptionsIntent);
}
private void getLocation(){
myLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
myLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,onLocation);
if (myLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
//Toast.makeText(getBaseContext(), "GPS Sudah Aktif.....", Toast.LENGTH_SHORT).show();
}
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportZoom(true);
mWebView.addJavascriptInterface(new Locater(this), "locater");
mWebView.loadUrl("file:///android_asset/appSHC.php");
String path="javascript:loadAtStart("+myLati+","+myLongi+",13)";
mWebView.loadUrl(path);
}
public class Locater {
Context mContext;
Locater(Context c) {
mContext = c;
}
public void showToast(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_LONG).show();
}
public String getLocation() throws JSONException {
JSONObject json=new JSONObject();
json.put("info0", "Posisi Anda "+myCity);
json.put("lat0", myLati);
json.put("lon0", myLongi);
json.put("info1", myCity2);
json.put("lat1",myLati2);
json.put("lon1", myLongi2);
return(json.toString());
}
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
finish();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport"
content="target-densitydpi=medium-dpi">
<title>APP-Hill Climbing</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAn4NVWkwfZqc6apKmk-YM-RTVksykdAS1hWJqLSw6oiFjM-DzvhR66TBi1NnEIxX6d6krYaiiLDFUTw"
type="text/javascript">
</script>
<script type="text/javascript">
var MLATI=-6.368351;
var MLONGI=106.830127;
var MLATI2=-6.353614;
var MLONGI2=106.831799;
var rev=new Array();
var swCycleTime=50;var sw,swObj,swct,swnow,swcycle;
var swObjAry=new Array();
(function() {
var shcsp;
var gebMap;
var directionsPanel;
var gebDirections;
var gebGeocoder;
var maxshcspSize = 24;
var maxSize = 10;
var maxTripSentry = 2000000000;
var avoidHighways = false;
var travelMode = G_TRAVEL_MODE_DRIVING;
var distIndex;
var isDone = false;
var reasons = new Array();
reasons[G_GEO_SUCCESS] = "Success";
reasons[G_GEO_BAD_REQUEST] = "Bad Request: A directions request could not be successfully parsed.";
reasons[G_GEO_SERVER_ERROR] = "Server error: The geocoding request could not be successfully processed.";
reasons[G_GEO_MISSING_QUERY] = "Missing Query: The HTTP q parameter was either missing or had no value.";
reasons[G_GEO_MISSING_ADDRESS] = "Missing Address: The address was either missing or had no value.";
reasons[G_GEO_UNKNOWN_ADDRESS] = "Unknown Address: No corresponding geographic location could be found for the specified address.";
reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address: The geocode for the given address cannot be returned due to legal or contractual reasons.";
reasons[G_GEO_BAD_KEY] = "Bad Key: The API key is either invalid or does not match the domain for which it was given";
reasons[G_GEO_TOO_MANY_QUERIES] = "Too Many Queries: The daily geocoding quota for this site has been exceeded.";
reasons[G_GEO_UNKNOWN_DIRECTIONS] = "Unknown Directions: The GDirections object could not compute directions between the points mentioned in the query.";
var waypoints = new Array();
var addresses = new Array();
var addr = new Array();
var wpActive = new Array();
var addressRequests = 0;
var wayStr;
var distances;
var durations;
var dist;
var dur;
var visited;
var distancematrix;
var bestPath;
var bestTrip;
var nextSet;
var numActive;
var chunkNode;
var cachedDirections = false;
var limit;
var onSolveCallback = function(){};
var originalOnFatalErrorCallback = function(shcsp, errMsg) { alert("Request failed: " + errMsg); }
var onFatalErrorCallback = originalOnFatalErrorCallback;
var doNotContinue = false;
var onLoadListener = null;
var onFatalErrorListener = null;
function shcApp(mode) {//shcWarshall
var alfa = 1.0;
var beta = 1.0;
var rho = 0.1;
var asymptoteFactor = 0.9;
var rute = new Array();
var nextRute = new Array();
var prob = new Array();
var numVertices = 100;
var numEdges = 10;
for (var i = 0; i < numActive; ++i) {
rute[i] = new Array();
nextRute[i] = new Array();
}
for (var i = 0; i < numActive; ++i) {
for (var j = 0; j < numActive; ++j) {
rute[i][j] = 1;
nextRute[i][j] = 0.0;
}
}
var lastNode = 0;
var startNode = 0;
var numSteps = numActive - 1;
var numValidDests = numActive;
if (mode == 1) {
lastNode = numActive - 1;
numSteps = numActive - 2;
numValidDests = numActive - 1;
}
for (var edge = 0; edge < numEdges; ++edge) {
for (var vertices = 0; vertices < numVertices; ++vertices) {
var curr = startNode;
var currdistance = 0;
for (var i = 0; i < numActive; ++i) {
visited[i] = false;
}
distancematrix[0] = curr;
for (var step = 0; step < numSteps; ++step) {
visited[curr] = true;
var cumProb = 0.0;
for (var next = 1; next < numValidDests; ++next) {
if (!visited[next]) {
//hitung jarak dua koordinat
prob[next] = Math.pow(rute[curr][next], alfa) * Math.pow(dur[curr][next], 0.0 - beta);
cumProb += prob[next];
}
}
var guess = Math.random() * cumProb;
var nextI = -1;
for (var next = 1; next < numValidDests; ++next) {
if (!visited[next]) {
nextI = next;
guess -= prob[next];
if (guess < 0) {
nextI = next;
break;
}
}
}
currdistance += dur[curr][nextI];
distancematrix[step+1] = nextI;
curr = nextI;
}
distancematrix[numSteps+1] = lastNode;
currdistance += dur[curr][lastNode];
// k2-rewire:
var lastStep = numActive;
if (mode == 1) {
lastStep = numActive - 1;
}
var changed = true;
var i = 0;
while (changed) {
changed = false;
for (; i < lastStep - 2 && !changed; ++i) {
var cost = dur[distancematrix[i+1]][distancematrix[i+2]];
var revMatrix = dur[distancematrix[i+2]][distancematrix[i+1]];
var iMatrix = dur[distancematrix[i]][distancematrix[i+1]];
var tmp, nowMatrix, newMatrix;
for (var j = i+2; j < lastStep && !changed; ++j) {
nowMatrix = cost + iMatrix + dur[distancematrix[j]][distancematrix[j+1]];
newMatrix = revMatrix + dur[distancematrix[i]][distancematrix[j]]+ dur[distancematrix[i+1]][distancematrix[j+1]];
if (nowMatrix > newMatrix) {
currdistance += newMatrix - nowMatrix;
for (var k = 0; k < Math.floor((j-i)/2); ++k) {
tmp = distancematrix[i+1+k];
distancematrix[i+1+k] = distancematrix[j-k];
distancematrix[j-k] = tmp;
}
changed = true;
--i;
}
cost += dur[distancematrix[j]][distancematrix[j+1]];
revMatrix += dur[distancematrix[j+1]][distancematrix[j]];
}
}
}
if (currdistance < bestTrip) {
bestPath = distancematrix;
bestTrip = currdistance;
}
for (var i = 0; i <= numSteps; ++i) {
nextRute[distancematrix[i]][distancematrix[i+1]] += (bestTrip - asymptoteFactor * bestTrip) / (numVertices * (currdistance - asymptoteFactor * bestTrip));
}
}
for (var i = 0; i < numActive; ++i) {
for (var j = 0; j < numActive; ++j) {
rute[i][j] = rute[i][j] * (1.0 - rho) + rho * nextRute[i][j];
nextRute[i][j] = 0.0;
}
}
}
}
function nextSetOf(num) {
var count = 0;
var ret = 0;
for (var i = 0; i < numActive; ++i) {
count += nextSet[i];
}
if (count < num) {
for (var i = 0; i < num; ++i) {
nextSet[i] = 1;
}
for (var i = num; i < numActive; ++i) {
nextSet[i] = 0;
}
} else {
// temukan satu yang pertama
var firstOne = -1;
for (var i = 0; i < numActive; ++i) {
if (nextSet[i]) {
firstOne = i;
break;
}
}
var firstZero = -1;
for (var i = firstOne + 1; i < numActive; ++i) {
if (!nextSet[i]) {
firstZero = i;
break;
}
}
if (firstZero < 0) {
return -1;
}
for (var i = 0; i < firstZero - firstOne - 1; ++i) {
nextSet[i] = 1;
}
for (var i = firstZero - firstOne - 1; i < firstZero; ++i) {
nextSet[i] = 0;
}
}
for (var i = 0; i < numActive; ++i) {
ret += (nextSet[i]<<i);
}
return ret;
}
function makeLatLng(latLng) {
return(latLng.toString().substr(1,latLng.toString().length-2));
}
function getWayStr(curr) {
var nextAbove = -1;
for (var i = curr + 1; i < waypoints.length; ++i) {
if (wpActive[i]) {
if (nextAbove == -1) {
nextAbove = i;
} else {
wayStr.push(makeLatLng(waypoints[i]));
wayStr.push(makeLatLng(waypoints[curr]));
}
}
}
if (nextAbove != -1) {
wayStr.push(makeLatLng(waypoints[nextAbove]));
getWayStr(nextAbove);
wayStr.push(makeLatLng(waypoints[curr]));
}
}
function getDistTable(curr, currInd) {
var nextAbove = -1;
var index = currInd;
for (var i = curr + 1; i < waypoints.length; ++i) {
if (wpActive[i]) {
index++;
if (nextAbove == -1) {
nextAbove = i;
} else {
dist[currInd][index] = distances[distIndex];
dur[currInd][index] = durations[distIndex++];
dist[index][currInd] = distances[distIndex];
dur[index][currInd] = durations[distIndex++];
}
}
}
if (nextAbove != -1) {
dist[currInd][currInd+1] = distances[distIndex];
dur[currInd][currInd+1] = durations[distIndex++];
getDistTable(nextAbove, currInd+1);
dist[currInd+1][currInd] = distances[distIndex];
dur[currInd+1][currInd] = durations[distIndex++];
}
}
function directions(mode) {
document.getElementById("my_textual_div").innerHTML = "";
document.getElementById("path").innerHTML = "";
document.getElementById("ordering").innerHTML = "";
if (cachedDirections) {
doshcsp(mode);
}
wayStr = new Array();
numActive = 0;
for (var i = 0; i < waypoints.length; ++i) {
if (wpActive[i]) ++numActive;
}
for (var i = 0; i < waypoints.length; ++i) {
if (wpActive[i]) {
wayStr.push(makeLatLng(waypoints[i]));
getWayStr(i);
break;
}
}
// Roundtrip
if (numActive > maxshcspSize) {
alert("Too many locations! You have " + numActive + ", but max limit is " + maxshcspSize);
} else {
distances = new Array();
durations = new Array();
chunkNode = 0;
nextChunk(mode);
}
}
function nextChunk(mode) {
if (chunkNode < wayStr.length) { ///..........tambah 1
var wayStrChunk = new Array();
for (var i = 0; i < maxSize && i + chunkNode < wayStr.length; ++i) {
wayStrChunk.push(wayStr[chunkNode+i]);
}
chunkNode += maxSize;
if (chunkNode < wayStr.length-1) {
chunkNode--;
} ///............
var myGebDirections = new GDirections(gebMap, directionsPanel);
GEvent.addListener(myGebDirections, "error", function() {
// locater.showToast('\''+myGebDirections.getStatus().code+'\'');
var errorMsg = reasons[myGebDirections.getStatus().code];
if (typeof errorMsg == 'undefined') errorMsg = 'Unknown error.';
var doNotContinue = true;
onFatalErrorCallback(shcsp, errorMsg);
});
GEvent.addListener(myGebDirections, "load", function() {
for (var i = 0; i < myGebDirections.getNumRoutes(); ++i) {
durations.push(myGebDirections.getRoute(i).getDuration().seconds); distances.push(myGebDirections.getRoute(i).getDistance().meters);
}
nextChunk(mode);
});
GEvent.addListener(myGebDirections, "addoverlay", function() {
// hilangkan standard google maps icons:
gebMap.clearOverlays();
directionsPanel.innerHTML = "";
});
myGebDirections.loadFromWaypoints(wayStrChunk, { getSteps:false, getPolyline:false, preserveViewport:true, avoidHighways:avoidHighways, travelMode:travelMode });
}else {
readyshcsp(mode);
}
}
function readyshcsp(mode) {
distIndex = 0;
dist = new Array();
dur = new Array();
numActive = 0;
for (var i = 0; i < waypoints.length; ++i) {
if (wpActive[i]) {
dist.push(new Array());
dur.push(new Array());
addr[numActive] = addresses[i];
numActive++;
}
}
for (var i = 0; i < numActive; ++i) {
dist[i][i] = 0;
dur[i][i] = 0;
}
for (var i = 0; i < waypoints.length; ++i) {
if (wpActive[i]) {
getDistTable(i, 0);
break;
}
}
doshcsp(mode);
}
function doshcsp(mode) {
// hitung roundtrip:
visited = new Array();
for (var i = 0; i < numActive; ++i) {
visited[i] = false;
}
distancematrix = new Array();
bestPath = new Array();
nextSet = new Array();
bestTrip = maxTripSentry;
visited[0] = true;
distancematrix[0] = 0;
cachedDirections = true;
shcApp(mode);
wayStrChunk = new Array();
var wpIndices = new Array();
for (var i = 0; i < waypoints.length; ++i) {
if (wpActive[i]) {
wpIndices.push(i);
}
}
var bestPathLatLngStr = "";
if(mode==1){
for (var i = 0; i < 2; ++i) {
//alert(bestPath[i]);
wayStrChunk.push(makeLatLng(waypoints[wpIndices[bestPath[i]]]));
bestPathLatLngStr += makeLatLng(waypoints[wpIndices[bestPath[i]]]) + "\n";
}
}
else
for (var i = 0; i < bestPath.length; ++i) {
//alert(bestPath[i]);
wayStrChunk.push(makeLatLng(waypoints[wpIndices[bestPath[i]]]));
bestPathLatLngStr += makeLatLng(waypoints[wpIndices[bestPath[i]]]) + "\n";
}
if (typeof onSolveCallback == 'function') {
if (onLoadListener)
GEvent.removeListener(onLoadListener);
onLoadListener = GEvent.addListener(gebDirections, 'addoverlay', function(){
onSolveCallback(shcsp);
});
}
if (onFatalErrorListener)
GEvent.removeListener(onFatalErrorListener);
onFatalErrorListener = GEvent.addListener(gebDirections, 'error', onFatalErrorCallback)
google.maps.Event.addListener(gebDirections, "addoverlay", function() {swStop('beg2');});
gebDirections.loadFromWaypoints(wayStrChunk, {getSteps:true, getPolyline:true, preserveViewport:false, avoidHighways:avoidHighways, travelMode:travelMode});
}
function addWaypoint(latLng) {
var freeInd = -1;
for (var i = 0; i < waypoints.length; ++i) {
if (!wpActive[i]) {
freeInd = i;
break;
}
}
if (freeInd == -1) {
if (waypoints.length < maxshcspSize) {
waypoints.push(latLng);
wpActive.push(true);
freeInd = waypoints.length-1;
} else {
return(-1);
}
} else {
waypoints[freeInd] = latLng;
wpActive[freeInd] = true;
}
return(freeInd);
}
BpshcspSolver.prototype.startOver = function() {
waypoints = new Array(); addresses = new Array();
addr = new Array(); wpActive = new Array();
wayStr = ""; distances = new Array();
durations = new Array();
dist = new Array();
dur = new Array();
visited = new Array();
distancematrix = new Array();
bestPath = new Array();
bestTrip = new Array();
nextSet = new Array();
numActive = 0;
chunkNode = 0;
addressRequests = 0;
cachedDirections = false;
onSolveCallback = function(){};
doNotContinue = false;
}
function BpshcspSolver(map, panel, onFatalError) {
if (shcsp) {
alert('Hanya Bisa membuat satu BpshcspSolver.');
return;
}
gebMap = map;
directionsPanel = panel;
gebGeocoder = new GClientGeocoder();
gebDirections = new GDirections(gebMap, directionsPanel);
onFatalErrorCallback = onFatalError; // only for errors fatal errors, not geocoding errors
shcsp = this;
}
BpshcspSolver.prototype.addWaypoint = function(latLng) {
addWaypoint(latLng);
};
BpshcspSolver.prototype.getWaypoints = function() {
var wp = [];
for (var i = 0; i < waypoints.length; i++) {
if (wpActive[i])
wp.push(waypoints[i]);
}
return wp;
};
BpshcspSolver.prototype.getAddresses = function() {
var addrs = [];
for (var i = 0; i < addresses.length; i++) {
if (wpActive[i])
addrs.push(addresses[i]);
}
return addrs;
};
BpshcspSolver.prototype.removeWaypoint = function(latLng) {
for (var i = 0; i < waypoints.length; ++i) {
if (wpActive[i] && waypoints[i].equals(latLng)) {
wpActive[i] = false;
return true;
}
}
return false;
};
BpshcspSolver.prototype.removeAddress = function(addr) {
for (var i = 0; i < addresses.length; ++i) {
if (wpActive[i] && addresses[i] == addr) {
wpActive[i] = false;
return true;
}
}
return false;
};
BpshcspSolver.prototype.getGDirections = function() {
return gebDirections;
};
BpshcspSolver.prototype.getOrder = function() {
return bestPath;
}
BpshcspSolver.prototype.getAvoidHighways = function() {
return avoidHighways;
}
BpshcspSolver.prototype.setAvoidHighways = function(avoid) {
avoidHighways = avoid;
}
BpshcspSolver.prototype.getTravelMode = function() {
return travelMode;
}
BpshcspSolver.prototype.setTravelMode = function(travelM) {
travelMode = travelM;
}
BpshcspSolver.prototype.getDurations = function() {
return dur;
}
BpshcspSolver.prototype.getTotalDuration = function() {
return gebDirections.getDuration().seconds;
}
BpshcspSolver.prototype.isReady = function() {
return addressRequests == 0;
};
BpshcspSolver.prototype.solveRoundTrip = function(callback) {
if (doNotContinue) {
alert('fatal errors.');
return;
}
if (!this.isReady()) {
setTimeout(function(){ shcsp.solveRoundTrip(callback) }, 20);
return;
}
if (typeof callback == 'function')
onSolveCallback = callback;
directions(0);
};
BpshcspSolver.prototype.solveAtoZ = function(callback) {
if (doNotContinue) {
alert('Cannot continue after fatal errors.');
return;
}
if (!this.isReady()) {
setTimeout(function(){ shcsp.solveAtoZ(callback) }, 20);
return;
}
if (typeof callback == 'function')
onSolveCallback = callback;
directions(1);
};
window.BpshcspSolver = BpshcspSolver;
})();
function formatTime(seconds) {
var days;
var hours;
var minutes;
days = parseInt(seconds / (24*3600));
seconds -= days * 24 * 3600;
hours = parseInt(seconds / 3600);
seconds -= hours * 3600;
minutes = parseInt(seconds / 60);
seconds -= minutes * 60;
var ret = "";
if (days > 0)
ret += days + " days ";
if (days > 0 || hours > 0)
ret += hours + " hrs ";
if (days > 0 || hours > 0 || minutes > 0)
ret += minutes + " min ";
if (days == 0 && hours == 0)
ret += seconds + " sec";
return(ret);
}
function formatLength(meters) {
var km = parseInt(meters / 1000);
meters -= km * 1000;
var ret = "";
if (km > 0)
ret += km + " km ";
if (km < 10)
ret += meters + " m";
return(ret);
}
function drawMarker(latlng,tit, num) {
var letter = num == 1 ? '' : '1';
var marker = new GMarker(latlng);
GEvent.addListener(marker, 'click', function() {
var info = tit;
gebMap.openInfoWindowHtml(latlng ,info);
});
return marker;
}
function setViewportToCover(waypoints) {
var bounds = new GLatLngBounds();
for (var i = 0; i < waypoints.length; ++i) {
bounds.extend(waypoints[i]);
}
gebMap.setCenter(bounds.getCenter());
gebMap.setZoom(gebMap.getBoundsZoomLevel(bounds));
}
///................................................................................ ditambah dari sini ini yg buat peta ga bisa munculXXXX
function loadAtStart2(lat, lng, lat2, lng2, zoom) {
if (GBrowserIsCompatible()) {
gebMap = new GMap2(document.getElementById("map"));
directionsPanel = document.getElementById("my_textual_div");
shcsp = new BpshcspSolver(gebMap, directionsPanel);
shcsp.startOver();
gebMap.setCenter(new GLatLng(lat, lng), zoom);
gebMap.addControl(new GLargeMapControl());
gebMap.addControl(new GMapTypeControl());
gebDirections = shcsp.getGDirections();
var posisi1 = new GLatLng(lat, lng);
shcsp.addWaypoint(posisi1);
gebMap.addOverlay(drawMarker(posisi1,'Posisi Anda',shcsp.getWaypoints().length));
var posisi2 = new GLatLng(lat2, lng2);
shcsp.addWaypoint(posisi2);
gebMap.addOverlay(drawMarker(posisi2,'Tujuan Anda',shcsp.getWaypoints().length));
//document.getElementById("my_textual_div").innerHTML = "";
//document.getElementById("path").innerHTML = "";
//document.getElementById("ordering").innerHTML = "";
directions(1, false, true,'Proses');
}
else {
alert('Your browser is not compatible with this technology.\nPlease consider upgrading.');
}
}
function loadAtStart(lat, lng, zoom) {
//locater.showToast('Load loadAtStart:'+lat+','+lng+'/'+zoom);
if (GBrowserIsCompatible()) {
gebMap = new GMap2(document.getElementById("map"));
directionsPanel = document.getElementById("my_textual_div");
shcsp = new BpshcspSolver(gebMap, directionsPanel);
var data=JSON.parse(locater.getLocation());
var a0=data.info0;
var b0=data.lat0;
var c0=data.lon0;
b0=b0.replace(",", "");
c0=c0.replace(",", "");
var b02 = parseFloat(b0);
var c02 = parseFloat(c0);
MLATI=b02;
MLONGI=c02;
lat=b02;
lng=c02;
var a1=data.info1;
var b1=data.lat1;
var c1=data.lon1;
b1=b1.replace(",", "");
c1=c1.replace(",", "");
var b12 = parseFloat(b1);
var c12 = parseFloat(c1);
MLATI2=b12;
MLONGI2=c12;
locater.showToast(a0+' to '+a1);
//gebMap.clearOverlays();////
shcsp.startOver();
gebMap.setCenter(new GLatLng(lat, lng), zoom);
gebMap.addControl(new GLargeMapControl());
gebMap.addControl(new GMapTypeControl());
gebDirections = shcsp.getGDirections();
var posisi1 = new GLatLng(lat, lng);
shcsp.addWaypoint(posisi1);
gebMap.addOverlay(drawMarker(posisi1,a0,shcsp.getWaypoints().length));
var posisi2 = new GLatLng(b12, c12);
shcsp.addWaypoint(posisi2);
gebMap.addOverlay(drawMarker(posisi2,a1,shcsp.getWaypoints().length));
//document.getElementById("my_textual_div").innerHTML = "";
//document.getElementById("path").innerHTML = "";
//document.getElementById("ordering").innerHTML = "";
//directions(0, document.forms['travelOpts'].walking.checked, document.forms ['travelOpts'].avoidHighways.checked,'Proses');
directions(1, false, true,'Proses');
}
else {
alert('Your browser is not compatible with this technology.\nPlease consider upgrading.');
}
}
function startOver() {
document.getElementById("my_textual_div").innerHTML = "";
document.getElementById("path").innerHTML = "";
document.getElementById("ordering").innerHTML = "";
gebMap.clearOverlays();
shcsp.startOver();
}
function directions(m, walking, avoid,toast) {
// locater.showToast(toast);
swReset('beg2');
swStart('beg2','+');
gebMap.clearOverlays();
shcsp.setAvoidHighways(avoid);
if (walking)
shcsp.setTravelMode(G_TRAVEL_MODE_WALKING);
else
shcsp.setTravelMode(G_TRAVEL_MODE_DRIVING);
gebMap.clearOverlays();
if (m == 0)
shcsp.solveRoundTrip(onSolveCallback);
else
shcsp.solveAtoZ(onSolveCallback);
}
function onSolveCallback(shcsp) {
var dir = shcsp.getGDirections();
// tampilkan roundtrip terdekat:
var pathStr = "<p>Trip duration: " + formatTime(dir.getDuration().seconds) + "<br>";
pathStr += "Trip length: " + formatLength(dir.getDistance().meters) + "</p>";
document.getElementById("path").innerHTML = pathStr;
var bestPathLatLngStr = "";
for (var i = 0; i < gebDirections.getNumGeocodes(); ++i) {
bestPathLatLngStr += "(" + gebDirections.getGeocode(i).Point.coordinates[1]
+ ", " + gebDirections.getGeocode(i).Point.coordinates[0] + ")\n";
}
orderStr = "";
for (var i = 0; i < shcsp.getOrder().length; ++i) {
orderStr += shcsp.getOrder()[i] + " ";
}
document.getElementById("ordering").innerHTML = orderStr;
isDone = true;
}
function isDone() {
return isDone;
}
function def(){
swReset('beg2');
swStart('beg2','+');
gebMap.clearOverlays();
document.getElementById("my_textual_div").innerHTML = "";
document.getElementById("path").innerHTML = "";
document.getElementById("ordering").innerHTML = "";
var distance=[];
var sortti=[];
myDir=new GDirections(gebMap,directionsPanel);
sortti.length=0;
for(i=1;i<rev.length;i++){
rev[i].dist=rev[0].distanceFrom(rev[i]);
}
rev= rev.sort(function (a,b) {return (a.dist- b.dist)});
google.maps.Event.addListener(myDir, "addoverlay", function() {
swStop('beg2');
});
for(i=0;i<2;i++){
myDir.loadFromWaypoints([rev[0],rev[1]]);
}
}
function swStart(id,ud){
swObj=document.getElementById(id);
swObj.style.color = "white";
swct=swObj.innerHTML.split(':');
swnow=new Date();
swObj.now=swnow.getTime();
swObj.reset=swObj.innerHTML;
swObj.ud=ud;
if (!isNaN(swObj.innerHTML)){
swObj.time=parseInt(swObj.innerHTML);
}
else if (swct.length==4){
swObj.time=(swct[0]*1000*60)+(swct[1]*1000*60)+(swct[2]*1000)+parseInt(swct[3]);
}
else if (swct.length==3){
swObj.time=(swct[0]*1000*60)+(swct[1]*1000)+parseInt(swct[2]);
}
else if (swct.length==2){
swObj.time=(swct[0]*1000)+parseInt(swct[1]);
}
else if (swct.length==1){
swObj.time=parseInt(swct[1]);
}
if (!swObj.time){
swObj.time=1;
}
if (!swObj.c){
swObj.c=ud;
swObjAry[swObjAry.length]=swObj;
}
}
function swStop(id){
swObj=document.getElementById(id);
swObj.style.color = "red";
if (!swObj.time){ return; }
swObj.time=null;
sw=new Date().getTime();
swObj.cycle+=(sw-swcycle);
if (swObj.ud=='-'){
swObj.cycle-=(sw-swcycle);
if (swObj.cycle<0){ swObj.cycle=0; }
}
swObj.innerHTML=(parseInt(swObj.cycle/1000/60/60)%60)+':'+(parseInt(swObj.cycle/1000/60)%60)+':'+((parseInt((swObj.cycle)/1000)%60)+':'+(swObj.cycle%1000));
}
function swReset(id,dt){
swObj=document.getElementById(id);
swObj.innerHTML=swObj.reset;
swObj.time=null;
}
function swCycle(){
swcycle=new Date().getTime();
for (sw0=0;sw0<swObjAry.length;sw0++){
if (swObjAry[sw0].time){
swObjAry[sw0].cycle=swObjAry[sw0].time+(swcycle-swObjAry[sw0].now);
if (swObjAry[sw0].ud=='-'){
swObjAry[sw0].cycle=swObjAry[sw0].time-(swcycle-swObjAry[sw0].now);
if (swObjAry[sw0].cycle<0){ swObjAry[sw0].cycle=0; swObjAry[sw0].time=0; }
}
swObjAry[sw0].innerHTML=(parseInt(swObjAry[sw0].cycle/1000/60/60)%60)+':'+(parseInt(swObjAry[sw0].cycle/1000/60)%60)+':'+((parseInt((swObjAry[sw0].cycle)/1000)%60)+':'+(swObjAry[sw0].cycle%1000));
}
}
}
setInterval('swCycle()',swCycleTime);
function init() {
isDone = false;
loadAtStart(MLATI,MLONGI,13);
}
function init2() {
isDone = false;
loadAtStart2(MLATI,MLONGI,MLATI2,MLONGI2,13);
}
</script>
</head>
<body onload='init()' onunload='GUnload()' bgcolor='#ff9999'>
<div id="map" style="width:100%; height: 320px"></div>
<br><br>
<form name="travelOpts">
<table>
<tr>
<td>
<input id="walking" type="radio" name="pilihdunk" >avoid Walking<br>
</td>
<td>
<input id="avoidHighways" type="radio" name="pilihdunk" checked="checked">avoid Highways<br>
</td>
</tr>
</table>
</form>
<table class="buttonTable">
<tr>
<td>
<input id="button1" type="button" value="Proses" onclick="directions(1, document.forms['travelOpts'].walking.checked, document.forms ['travelOpts'].avoidHighways.checked,'Proses')">
</td>
<td>
<input id="button2"
type="button"
value="Reset"
onclick="init2()">
</td>
<td>
</td>
</tr>
</table>
<div id="path">
</div>
<div id="ordering">
</div>
<div id="my_textual_div">
</div>
<div id="beg2"
style="color:#ffffff">
</div>
</body>
</html>
Tidak ada komentar:
Posting Komentar