Clash of Clans tool details:
- Unlimited Gems
- Unlimited Resources
- Speed up Shield
- Automatic update
- Anti-Ban protection
- Simple and user friendly
- Tested and fully working with an accurate of 100% working rate
Read more and download . . .
package id.web.twoh.www.mapsv2;
import java.io.InputStream;
import java.util.ArrayList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.google.android.gms.maps.model.LatLng;
import android.annotation.SuppressLint;
import android.util.Log;
@SuppressLint("NewApi")
public class MapDirection {
public final static String MODE_DRIVING = "driving";
public final static String MODE_WALKING = "walking";
public MapDirection() { }
public Document getDocument(LatLng start, LatLng end, String mode) {
String url = "http://maps.googleapis.com/maps/api/directions/xml?"
+ "origin=" + start.latitude + "," + start.longitude
+ "&destination=" + end.latitude + "," + end.longitude
+ "&sensor=false&units=metric&mode=driving";
try {
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost(url);
HttpResponse response = httpClient.execute(httpPost, localContext);
InputStream in = response.getEntity().getContent();
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(in);
return doc;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public String getDurationText (Document doc) {
NodeList nl1 = doc.getElementsByTagName("duration");
Node node1 = nl1.item(nl1.getLength() - 1);
NodeList nl2 = node1.getChildNodes();
Node node2 = nl2.item(getNodeIndex(nl2, "text"));
Log.i("DurationText", node2.getTextContent());
return node2.getTextContent();
}
public int getDurationValue (Document doc) {
NodeList nl1 = doc.getElementsByTagName("duration");
Node node1 = nl1.item(nl1.getLength() - 1);
NodeList nl2 = node1.getChildNodes();
Node node2 = nl2.item(getNodeIndex(nl2, "value"));
Log.i("DurationValue", node2.getTextContent());
return Integer.parseInt(node2.getTextContent());
}
public String getDistanceText (Document doc) {
NodeList nl1 = doc.getElementsByTagName("distance");
Node node1 = nl1.item(nl1.getLength() - 1);
NodeList nl2 = node1.getChildNodes();
Node node2 = nl2.item(getNodeIndex(nl2, "text"));
Log.i("DistanceText", node2.getTextContent());
return node2.getTextContent();
}
public int getDistanceValue (Document doc) {
NodeList nl1 = doc.getElementsByTagName("distance");
Node node1 = nl1.item(nl1.getLength() - 1);
NodeList nl2 = node1.getChildNodes();
Node node2 = nl2.item(getNodeIndex(nl2, "value"));
Log.i("DistanceValue", node2.getTextContent());
return Integer.parseInt(node2.getTextContent());
}
public String getStartAddress (Document doc) {
NodeList nl1 = doc.getElementsByTagName("start_address");
Node node1 = nl1.item(0);
Log.i("StartAddress", node1.getTextContent());
return node1.getTextContent();
}
public String getEndAddress (Document doc) {
NodeList nl1 = doc.getElementsByTagName("end_address");
Node node1 = nl1.item(0);
Log.i("StartAddress", node1.getTextContent());
return node1.getTextContent();
}
public String getCopyRights (Document doc) {
NodeList nl1 = doc.getElementsByTagName("copyrights");
Node node1 = nl1.item(0);
Log.i("CopyRights", node1.getTextContent());
return node1.getTextContent();
}
public ArrayList getDirection (Document doc) {
NodeList nl1, nl2, nl3;
ArrayList listGeopoints = new ArrayList();
nl1 = doc.getElementsByTagName("step");
if (nl1.getLength() > 0) {
for (int i = 0; i < nl1.getLength(); i++) {
Node node1 = nl1.item(i);
nl2 = node1.getChildNodes();
Node locationNode = nl2.item(getNodeIndex(nl2, "start_location"));
nl3 = locationNode.getChildNodes();
Node latNode = nl3.item(getNodeIndex(nl3, "lat"));
double lat = Double.parseDouble(latNode.getTextContent());
Node lngNode = nl3.item(getNodeIndex(nl3, "lng"));
double lng = Double.parseDouble(lngNode.getTextContent());
listGeopoints.add(new LatLng(lat, lng));
locationNode = nl2.item(getNodeIndex(nl2, "polyline"));
nl3 = locationNode.getChildNodes();
latNode = nl3.item(getNodeIndex(nl3, "points"));
ArrayList arr = decodePoly(latNode.getTextContent());
for(int j = 0 ; j < arr.size() ; j++) {
listGeopoints.add(new LatLng(arr.get(j).latitude, arr.get(j).longitude));
}
locationNode = nl2.item(getNodeIndex(nl2, "end_location"));
nl3 = locationNode.getChildNodes();
latNode = nl3.item(getNodeIndex(nl3, "lat"));
lat = Double.parseDouble(latNode.getTextContent());
lngNode = nl3.item(getNodeIndex(nl3, "lng"));
lng = Double.parseDouble(lngNode.getTextContent());
listGeopoints.add(new LatLng(lat, lng));
}
}
return listGeopoints;
}
private int getNodeIndex(NodeList nl, String nodename) {
for(int i = 0 ; i < nl.getLength() ; i++) {
if(nl.item(i).getNodeName().equals(nodename))
return i;
}
return -1;
}
private ArrayList decodePoly(String encoded) {
ArrayList poly = new ArrayList();
int index = 0, len = encoded.length();
int lat = 0, lng = 0;
while (index < len) {
int b, shift = 0, result = 0;
do {
b = encoded.charAt(index++) - 63;
result |= (b & 0x1f) << shift;
shift += 5;
} while (b >= 0x20);
int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
lat += dlat;
shift = 0;
result = 0;
do {
b = encoded.charAt(index++) - 63;
result |= (b & 0x1f) << shift;
shift += 5;
} while (b >= 0x20);
int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
lng += dlng;
LatLng position = new LatLng((double) lat / 1E5, (double) lng / 1E5);
poly.add(position);
}
return poly;
}
}
Pada dasarnya, kelas tersebut akan menerima inputan berupa dua buah
koordinat, titik awal dan titik akhir. Untuk kemudian di decode
menggunakan Google Maps APIs, yang menghasilkan sebuah file XML. Nah, selanjutnya XML tersebut akan diubah menjadi sebuah ArrayList berisi LatLng (titik
koordinat latitude dan longitude). Nantinya array dari latitude dan
longitude itulah yang akan digunakan untuk menampilkan rute pada Android
Maps V2.//...
// sediakan dua buah koordinat
LatLng TENDEAN = new LatLng(-6.248000,106.8322);
LatLng MONAS = new LatLng(-6.1755, 106.8273);
// inisialisasi kelas
MapDirection MapDirection md = new MapDirection();
LatLng source = TENDEAN;
//download document XML
Document doc = md.getDocument(source, MONAS, MapDirection.MODE_DRIVING);
// menggunakan mode driving
// method untuk mendapatkan point direction / rute
ArrayList directionPoint = md.getDirection(doc);
// konfigurasi rute, warna garis, ketebalan, dan sebagainya
PolylineOptions rectLine = new PolylineOptions().width(5).color(Color.RED);
// looping pada array koordinat direction point, dan menambahkannya ke PolyLineOptions
for (int i = 0; i < directionPoint.size(); i++)
{
rectLine.add(directionPoint.get(i));
}
// menampilkan rute di peta yang kita buat
googleMap.addPolyline(rectLine);
//....
Begitulah caranya, pada kode di atas pertama-tama kita akan meminta
Document XML-nya terlebih dahulu dengan memanggil fungsi
getDocument(source,destination). Setelah kita mendapatkan document xml
tersebut, baru kita parsing menjadi array koordinat lat long menggunakan
fungsi getDirection(doc).
Sebagai pengantar bagi yang belum pernah membuat Aplikasi Peta GoogleMap Versi 2 sebaiknya Membaca dahulu Artikel Ini.
Berdasarkan project dari Artikel tersebut, sekarang kita tambahkan
Fasilitas Rute. Untuk mudahnya dalam pembuatan, sebenarnya fasilitas
rute ini ditampilkan dengan cara Aplikasi buatan kita memanggil Aplikasi
lain yang memiliki fasilitas Route Direction bisa Maps milik Google
Android atau Aplikasi Web Maps.Google.com, Membuat Garis Rute Direction
Sendiri di Atas Peta GoogleMap kita sebenarnya bisa, tetapi terlalu
sulit, dan lama, harus memparsing informasi Direction dari Google Map.package com.amijaya.googlemapv2;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnInfoWindowClickListener;
import com.google.android.gms.maps.GoogleMap.OnMarkerClickListener;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.view.Menu;
import android.widget.Toast;
//http://cariprogram.blogspot.com
//nuramijaya@gmail.com
public class MainActivity extends FragmentActivity {
final int RQS_GooglePlayServices = 1;
private GoogleMap myMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager myFragmentManager = getSupportFragmentManager();
SupportMapFragment mySupportMapFragment =
(SupportMapFragment)myFragmentManager.findFragmentById(R.id.map);
myMap = mySupportMapFragment.getMap();
LatLng jogja = new LatLng(-7.782939, 110.367050);
MarkerOptions markerJogja = new MarkerOptions();
markerJogja.position(jogja);
markerJogja.title("Tugu Yogyakarta");
markerJogja.snippet("Tugu Pusat Kota Yogyakarta");
markerJogja.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
myMap.addMarker(markerJogja);
LatLng amplaz = new LatLng(-7.783130530640776, 110.40135302698059);
MarkerOptions markerAmplaz = new MarkerOptions();
markerAmplaz.position(amplaz);
markerAmplaz.title("Ambarrukmo Plaza");
markerAmplaz.snippet("Ambarrukmo Plaza Yogyakarta");
markerAmplaz.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
myMap.addMarker(markerAmplaz);
myMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
myMap.getUiSettings().setCompassEnabled(true);
myMap.getUiSettings().setZoomControlsEnabled(true);
myMap.getUiSettings().setMyLocationButtonEnabled(true);
myMap.setMyLocationEnabled(true);
myMap.animateCamera(CameraUpdateFactory.newLatLngZoom(jogja, 15));
myMap.setOnMarkerClickListener(new OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker arg0) {
// TODO Auto-generated method stub
try {
StringBuilder urlString = new StringBuilder();
String daddr = (String.valueOf(arg0.getPosition().latitude)+",
"+String.valueOf(arg0.getPosition().longitude));
urlString.append("http://maps.google.com/maps?f=d&hl=en");
urlString.append("&saddr="+String.valueOf(myMap.getMyLocation().
getLatitude())+","+String.valueOf(myMap.getMyLocation().getLongitude()));
urlString.append("&daddr="+daddr);
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(urlString.toString()));
startActivity(i);
} catch (Exception ee) {
Toast.makeText(getApplicationContext(),
"Lokasi Saat Ini Belum Didapatkan, Coba Nyalakan GPS, Keluar Ruangan dan Tunggu Beberapa Saat",
Toast.LENGTH_LONG).show();
}
return false;
}
});
myMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker arg0) {
// TODO Auto-generated method stub
//JIKA KLIKNYA INGIN DI INFO WINDOW
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
Setelah itu buat layout di activity_main.xml sebagai berikut :
Untuk AndroidManifest.xml kita setting seperti ini, ingat untuk mengganti Google Map Key dengan milik anda sendiri agar sesuai dengan SDK di komputer anda.
Jangan lupa hidupkan GPS dan Internet, tunggu beberapa saat sampai mendapatkan sinyal GPS, jika belum mendapatkan tetapi sudah diklik markernya hasilnya seperti ini :