Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何为latlng google maps v2 android从asset到double获取字符串_Android_String_Google Maps_Double - Fatal编程技术网

如何为latlng google maps v2 android从asset到double获取字符串

如何为latlng google maps v2 android从asset到double获取字符串,android,string,google-maps,double,Android,String,Google Maps,Double,我是android编程新手,我尝试在google maps v2 android上绘制一条多段线。坐标(超过100)存储在ASTES目录中的两个txt文件中(一个txt用于lat,一个用于lng)。我尝试以字符串形式加载文件内容,但现在不知道如何将这些内容转换为多段线功能的双精度。 Double.parseDouble(contentdlat);不行 txt的ar中的坐标以“,”分隔,看起来像: dlat.txt=42.4630,42.4539 dlng.txt=-75.0572,-73.973

我是android编程新手,我尝试在google maps v2 android上绘制一条多段线。坐标(超过100)存储在ASTES目录中的两个txt文件中(一个txt用于lat,一个用于lng)。我尝试以字符串形式加载文件内容,但现在不知道如何将这些内容转换为多段线功能的双精度。 Double.parseDouble(contentdlat);不行

txt的ar中的坐标以“,”分隔,看起来像:

dlat.txt=42.4630,42.4539

dlng.txt=-75.0572,-73.9737

更新:现在我只使用一个文件,而不是两个

coord_short.txt=42.4630,-75.0572,42.4539,-73.9737

旧代码如下所示:

//Add Polyline
         ArrayList<LatLng> all=new ArrayList<LatLng>();
         ArrayList<Double> lat1=new ArrayList<Double>();
         ArrayList<Double> lon=new ArrayList<Double>();

         AssetManager assetManager = getAssets();

         // To load dlat text file
         InputStream inputdlat;
         try {
         inputdlat = assetManager.open("dlat.txt");

         int sizedlat = inputdlat.available();
         byte[] bufferdlat = new byte[sizedlat];
         inputdlat.read(bufferdlat);
         inputdlat.close();

         // byte buffer into a string
         String contentdlat = new String(bufferdlat);
         Toast.makeText(this, contentdlat, Toast.LENGTH_SHORT).show();
         //String[] splitdlat = contentdlat.split(",");

         }
         catch (IOException e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
                 }


        // To load dlng text file
         InputStream inputdlng;
         try {
         inputdlng = assetManager.open("dlng.txt");

         int sizedlng = inputdlng.available();
         byte[] bufferdlng = new byte[sizedlng];
         inputdlng.read(bufferdlng);
         inputdlng.close();

         // byte buffer into a string
         String contentdlng = new String(bufferdlng);
         Toast.makeText(this, contentdlng, Toast.LENGTH_SHORT).show();
         //String[] splitdlng = contentdlng.split(",");

         }
         catch (IOException e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
                 }

         double dlat = Double.parseDouble(contentdlat);
         double dlat = Double.parseDouble(contentdlng);

         //double[] dlat = {42.4630,42.4539};
         //double[] dlon = new double[]{-75.0572,-73.9737};

         for(double n : dlat){
         lat1.add(n);
         }

         for(double n : dlon){
         lon.add(n);
         }

         for(int a=0;a<lat1.size();a++)
         {
         LatLng allLatLng= new LatLng(lat1.get(a),lon.get(a));
         all.add(allLatLng);
         }

         Polyline polyline = map.addPolyline(new PolylineOptions()
         .addAll(all)
         .width(8)
         .color(Color.GREEN));
但现在我的多段线没有在地图上绘制


现在有什么问题?

资产文件夹中有两个不同的纬度和经度文件吗?一个是纬度文件(dlat.txt),另一个是经度文件(dlng.txt)。但通常在这个dlat.txt=42.4630,42.4539文件中,纬度和经度是可用的。。。因此,这两个坐标是lat,在dlng.txt中有所需的lng。这就是我想要的。但是,当我可以在一个文件中执行此操作,并使用“,”将其拆分时,我也可以将其保存到一个文本文件中。这段代码与我的代码类似,区别在哪里?
InputStream is = getAssets().open("test.txt");
int size = is.available();
byte[] buffer = new byte[size]; //declare the size of the byte array with size of the file
is.read(buffer); //read file
is.close(); //close file

// Store text file data in the string variable
    String str_data = new String(buffer);
InputStream is = getAssets().open("test.txt");
int size = is.available();
byte[] buffer = new byte[size]; //declare the size of the byte array with size of the file
is.read(buffer); //read file
is.close(); //close file

// Store text file data in the string variable
    String str_data = new String(buffer);