0
我有我的地圖很多位置指針現在我想通過專線將所有這些指針相互連接我的地圖是這樣的截圖中看到這個截圖enter image description here如何繪製指針之間的路徑線被
上面的截圖我的地圖,現在我要畫的指針我要讓這樣enter image description here 我的地圖Java代碼下面是我能做些什麼,在地圖上畫出路線線
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
http = new Http();
sharedPreferences = getSharedPreferences("dbapp", MODE_PRIVATE);
avatarName= (TextView) findViewById(R.id.mProfiletv);
profileName= (TextView) findViewById(R.id.mActName);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
Intent mapScreen= getIntent();
stringID=mapScreen.getStringExtra("ID");
Log.d(MainActivity.LOG_TAG,"[MapActivity::onCreate()]UID List:"+ stringID);
userDetail=null;
try {
userDetail = new JSONObject(mapScreen.getStringExtra("jsonform"));
profileName.setText(userDetail.getString("name"));
String test = userDetail.getString("name");
String s=test.substring(0,1);
avatarName.setText(s);
avatarName.setBackgroundColor(Integer.parseInt(mapScreen.getStringExtra("color")));
} catch (JSONException e) {
e.printStackTrace();
Log.d(MainActivity.LOG_TAG,"Exception:"+e.getMessage());
}
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
new AsyncTask<Void, Void, String>() {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(Void... params) {
String response;
String body = "UID=" + stringID;
response = http.postRequest(HttpConfigs.URL_COORDINATES, body);
return response;
}
@Override
protected void onPostExecute(String response) {
super.onPostExecute(response);
try {
final JSONObject responseJson = new JSONObject(response);
remoteMessage = responseJson.getString("message");
if (responseJson.getBoolean("result")) {
JSONArray data = responseJson.getJSONArray("data");
Log.d(MainActivity.LOG_TAG,"Map DATA"+data.toString());
//Log.d(MainActivity.LOG_TAG, data.toString());
//Log.d(MainActivity.LOG_TAG, "Testing "+ data.length());
//Log.d(MainActivity.LOG_TAG, "Testing "+ data.length());
for (int i = 0; i < data.length(); i++) {
String lon = data.getJSONObject(i).getString("lon");
String lat = data.getJSONObject(i).getString("lat");
String time = data.getJSONObject(i).getString("time");
LatLng loc = new LatLng(Double.parseDouble(lat), Double.parseDouble(lon));
mMap.addMarker(new MarkerOptions().position(loc).title("Marker: "+i+" "+time));
if (i == data.length() - 1)
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(loc, 13));
}
} else {
showMessage(remoteMessage);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}.execute();