나는 안드로이드 프로그래밍에 익숙하지 않고 Google지도 v2 android에서 폴리 라인을 그리려고합니다. 좌표 (100 개 이상)는 asstes 디렉토리에 두 개의 txt 파일 (lat에 대해 하나의 txt와 lng에 하나)에 저장됩니다. 문자열의 파일 내용을로드하려고했지만 지금은 폴리선 기능에 대해 이중으로 변환하는 방법이 없습니다. Double.parseDouble (contentdlat); 작동하지 않습니다!Google Maps v2 android
는 A ","와 TXT의 아칸소 seperatet의 좌표와 같이 보인다 :
dlat.txt = 42.4630,42.4539
dlng.txt = -75.0572, -73.9737
UPDATE : 이제는 두 개 대신 하나의 파일 만 사용합니다.
coord_short.txt = 이전 코드는 다음과 같습니다 -73.9737
42.4630, -75.0572,42.4539 :
//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));
누군가가 나를 도울 수 있다면 그것은 좋은 것입니다. 피 유시 굽타의 도움으로 확인
는 난에 코드를 변경 : AssetManager assetManager = getAssets();
// To load coordinate text with hundreds of coordinates file like
InputStream input;
try {
input = assetManager.open("coord_short.txt");
int size = input.available();
byte[] buffer = new byte[size];
input.read(buffer);
input.close();
// byte buffer into a string
String content = new String(buffer);
String[] separated = content.split(",");
String latString = separated[0];
String longString = separated[1];
double coordlat = Double.parseDouble(latString);
double coordlon = Double.parseDouble(longString);
LatLng coordlocation = new LatLng(coordlat, coordlon);
Polyline polyline = map.addPolyline(new PolylineOptions()
.add(coordlocation)
.width(8)
.color(Color.GREEN));
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
하지만 지금 내 폴리 라인은지도에 그려지지 않습니다.
지금 뭐야?
자산 폴더에 두 개의 다른 위도와 경도 파일이 있습니까 ?? – Piyush
위도 (dlat.txt)와 경도 (dlng.txt)가있는 파일이 하나씩 있습니다. – Schmidt
하지만 일반적으로이 dlat.txt = 42.4630,42.4539 파일의 위도와 경도를 사용할 수 있습니다 ... – Piyush