作者:宝贝猪雯 | 来源:互联网 | 2023-05-18 19:33
IhaveaJSONfileinwhichIhavearound1800paths.In1paththereareseveralpointslikeasing
I have a JSON file in which I have around 1800 paths. In 1 path there are several points like a single has.
我有一个JSON文件,其中有大约1800条路径。在一条路径中有几个点。
I have done this code
我做了这个代码
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;
import com.golfcart.bean.VillagesListBean;
import com.golfcart.utils.JSONParser;
import com.golfcart.utils.UtilFunction;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.model.Polyline;
import com.google.android.gms.maps.model.PolylineOptions;
public class MyNavigationGolfcart extends FragmentActivity implements OnClickListener {
private GoogleMap googleMap;
double sourcelat, sourcelng, destlat, destlng;
private String result1;
boolean flag = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mynav);
addMap();
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
getPath();
}
}).start();
}
private void getPath() {
BufferedReader br;
try {
br = new BufferedReader(new InputStreamReader(getAssets()
.open("finalpath.txt")));
String strLine = null;
String s = "";
while ((strLine = br.readLine()) != null) {
s = s + strLine;
}
JSONObject json = new JSONObject(s);
if (json != null) {
JSONArray features = json.getJSONArray("features");
for (int i = 0; i 0) {
MyNavigationGolfcart.this.runOnUiThread(new Runnable() {
@Override
public void run() {
if (flag) {
try {
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(array.getJSONArray(0).getDouble(1), array.getJSONArray(0).getDouble(0)), 12));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
flag = false;
}
for (int z = 0; z
What I did initially I add the map using addmap()
then I get the JSON from the file in which I have 1800 paths.
首先,我使用addmap()添加了映射,然后从我有1800条路径的文件中获取JSON。
Then I took a path and draw on map using polyline
. I am not getting what is wrong in my code.
然后我用折线画出了一条路径。我不知道我的代码有什么问题。
1 个解决方案