3

次の形式のデータがあります。

POINT(73.0166738279393 33.6788721326803)
MULTILINESTRING((73.0131224998036 33.679001500419,73.0119635003153 33.678392400389,73.0119205001311 33.6783781002692),(73.0131224998036 33.679001500419,73.0136031002029 33.6783443999742),(73.0136031002029 33.6783443999742,73.0147099372139 33.67685138958),(73.0147099372139 33.67685138958,73.0150124997272 33.6770292997624,73.0154158996241 33.6773507003746,73.0157677998441 33.6776577999676,73.016042399737 33.6779721004322,73.0162998999205 33.6783149004124,73.0166738279393 33.6788721326803))

AndroidのGoogleマップに描画したいと思います。名前と座標の配列を作成します。

ArrayList<String> coordinates = new ArrayList<String>
coordinates.add(tvcoor.getText().toString());

これによりエラーが発生します。アプリケーションを実行すると、強制的に停止します。そして、どうすればそれを地図に描くことができますか?

4

5 に答える 5

2

これを試して 、

String str;
ArrayList<String> coordinates = new ArrayList<String>();

最初にテキストビューから文字列を取得します。

str = textview.getText().toString();

次にブラケットを取り外します。

str = str.replaceAll("\\(", "");
str = str.replaceAll("\\)", "");

次にカンマで区切り、arraylist に値を追加します。

String[] commatokens = str.split(",");
        for (String commatoken : commatokens) {
            System.out.println("-" + commatoken + "-");
            coordinates.add(commatoken);
        }

次に、インデックス位置で別の座標値を取得し、

 for (int i = 0; i < coordinates.size(); i++) {

            String[] tokens = coordinates.get(i).split("\\s");
            for (String token : tokens) {
                System.out.println("-" + token + "-");
            }
        }
于 2012-09-17T07:51:24.567 に答える
0

彼の答えは私をとても助けたので、ポールの答えを拡張するだけです...

private void setUpMap(SomeObjectWithLocationAsWKT r) {

    List<LatLng> points = new ArrayList<LatLng>();
    WKTReader wktReader = new WKTReader();
    LineString line = null;
    Coordinate lineCentroid = null;
    Coordinate[] lineCoordinates = null;

    // if our object's WKT geometry is not null - map it
    if (r.geowkt != null) {

        // use the JTS (Java Topology Suite) WKTReader to read that WKT!
        try {
            line = (LineString) wktReader.read(r.geowkt);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        // using (JTS) again to getCoordinates of the linestring
        lineCoordinates = line.getCoordinates();

        // Iterate through the line's coordinates & assign to List<LatLng> points
        for(Coordinate coordinate : lineCoordinates){
            points.add(new LatLng(coordinate.x, coordinate.y));
        }

        // add Polyline to Google Map
        Polyline p = mMap.addPolyline(
        new PolylineOptions()
        .addAll(points)
        .width(4)
        .color(Color.RED));
    }
}

// an example of zooming to the centroid of the WKT geometry 
// again, using (JTS - Java Topology Suite)
private void handleNewLocation(Location location) {
    LatLng latLng = null; 
    WKTReader wktReader = new WKTReader();
    LineString line = null;
    Coordinate lineCentroid = null; 

    // if our object's WKT geometry is not null - zoom to it
    if (r.geowkt != null) {
        try {
            line = (LineString) wktReader.read(r.geowkt);
            lineCentroid = line.getCentroid().getCoordinate();
            latLng = new LatLng(lineCentroid.x, lineCentroid.y);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else {
        // just default to whatever location was passed in
        Log.d(TAG, location.toString());
        double currentLatitude = location.getLatitude();
        double currentLongitude = location.getLongitude();
        latLng = new LatLng(currentLatitude, currentLongitude);
    }
    CameraUpdate yourLocation = CameraUpdateFactory.newLatLngZoom(latLng, 19);
    mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
    mMap.animateCamera(yourLocation);
}
于 2015-10-30T16:52:06.647 に答える