0

Androidを使用してGoogleマップにパスを描画しようとしていますが、このコードをオンラインで見つけましたが、エラーが発生して修正できません.ポイントのクラスとRoadProviderのクラスを作成しましたが、組み込みのクラスポイントとポイント彼の間で混乱します作成しました。ここにエラーがあります

 Description    Resource    Path    Location    Type
mDescription cannot be resolved or is not a field   RoadProvider.java   /sbn/src/sbn/project/gp line 103    Java Problem
mIconUrl cannot be resolved or is not a field   RoadProvider.java   /sbn/src/sbn/project/gp line 109    Java Problem
mLatitude cannot be resolved or is not a field  RoadProvider.java   /sbn/src/sbn/project/gp line 117    Java Problem
mLongitude cannot be resolved or is not a field RoadProvider.java   /sbn/src/sbn/project/gp line 118    Java Problem
mName cannot be resolved or is not a field  RoadProvider.java   /sbn/src/sbn/project/gp line 90 Java Problem
The method addPoint(Point[]) in the type KMLHandler is not applicable for the arguments (Point[])   RoadProvider.java   /sbn/src/sbn/project/gp line 68 Java Problem
The method addPoint(Point[]) in the type KMLHandler is not applicable for the arguments (Point[])   RoadProvider.java   /sbn/src/sbn/project/gp line 69 Java Problem

アナ、ここにコードがあります

package sbn.project.gp;

public class Point {

    String mName;
    String mDescription;
    String mIconUrl;
    double mLatitude;
    double mLongitude;
}

そして、これは RoadProvider クラスです

public class RoadProvider {

        public static Road getRoute(InputStream is) {
            KMLHandler handler = new KMLHandler();
            try {
                    SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
                    parser.parse(is, handler);
            } catch (ParserConfigurationException e) {
                    e.printStackTrace();
            } catch (SAXException e) {
                    e.printStackTrace();
            } catch (IOException e) {
                    e.printStackTrace();
            }
            return handler.mRoad;
    }

    public static String getUrl(double fromLat, double fromLon, double toLat,
                    double toLon) {// connect to map web service
            StringBuffer urlString = new StringBuffer();
            urlString.append("http://maps.google.com/maps?f=d&hl=en");
            urlString.append("&saddr=");// from
            urlString.append(Double.toString(fromLat));
            urlString.append(",");
            urlString.append(Double.toString(fromLon));
            urlString.append("&daddr=");// to
            urlString.append(Double.toString(toLat));
            urlString.append(",");
            urlString.append(Double.toString(toLon));
            urlString.append("&ie=UTF8&0&om=0&output=kml");
            return urlString.toString();
    }
    }

    class KMLHandler extends DefaultHandler {
    Road mRoad;
    boolean isPlacemark;
    boolean isRoute;
    boolean isItemIcon;
    private Stack mCurrentElement = new Stack();
    private String mString;

    public KMLHandler() {
            mRoad = new Road();
    }

    public void startElement(String uri, String localName, String name,
                    Attributes attributes) throws SAXException {
            mCurrentElement.push(localName);
            if (localName.equalsIgnoreCase("Placemark")) {
                    isPlacemark = true;

                    mRoad.mPoints=addPoint(mRoad.mPoints);//there is an error here
                    mRoad.mPoints = addPoint(mRoad.mPoints);//there is an error here
            } else if (localName.equalsIgnoreCase("ItemIcon")) {
                    if (isPlacemark)
                            isItemIcon = true;
            }
            mString = new String();
    }

    public void characters(char[] ch, int start, int length)
                    throws SAXException {
            String chars = new String(ch, start, length).trim();
            mString = mString.concat(chars);
    }

    public void endElement(String uri, String localName, String name)
                    throws SAXException {
            if (mString.length() > 0) {
                    if (localName.equalsIgnoreCase("name")) {
                            if (isPlacemark) {
                                    isRoute = mString.equalsIgnoreCase("Route");
                                    if (!isRoute) {
                                            mRoad.mPoints[mRoad.mPoints.length - 1].mName = mString; //there is an error here  
                                    }
                            } else {
                                    mRoad.mName = mString;
                            }
                    } else if (localName.equalsIgnoreCase("color") && !isPlacemark) {
                            mRoad.mColor = Integer.parseInt(mString, 16);
                    } else if (localName.equalsIgnoreCase("width") && !isPlacemark) {
                            mRoad.mWidth = Integer.parseInt(mString);
                    } else if (localName.equalsIgnoreCase("description")) {
                            if (isPlacemark) {
                                    String description = cleanup(mString);
                                    if (!isRoute)
                                            mRoad.mPoints[mRoad.mPoints.length - 1].mDescription = description;//there is an error here 
                                    else
                                            mRoad.mDescription = description;//there is an error here 
                            }
                    } else if (localName.equalsIgnoreCase("href")) {
                            if (isItemIcon) {
                                    mRoad.mPoints[mRoad.mPoints.length - 1].mIconUrl = mString;
                            }
                    } else if (localName.equalsIgnoreCase("coordinates")) {
                            if (isPlacemark) {
                                    if (!isRoute) {
                                            String[] xyParsed = split(mString, ",");
                                            double lon = Double.parseDouble(xyParsed[0]);
                                            double lat = Double.parseDouble(xyParsed[1]);
                                            mRoad.mPoints[mRoad.mPoints.length - 1].mLatitude = lat;
                                            mRoad.mPoints[mRoad.mPoints.length - 1].mLongitude = lon;
                                    } else {
                                            String[] coodrinatesParsed = split(mString, " ");
                                            int lenNew = coodrinatesParsed.length;
                                            int lenOld = mRoad.mRoute.length;
                                            double[][] temp = new double[lenOld + lenNew][2];
                                            for (int i = 0; i < lenOld; i++) {
                                                    temp[i] = mRoad.mRoute[i];
                                            }
                                            for (int i = 0; i < lenNew; i++) {
                                                    String[] xyParsed = split(coodrinatesParsed[i], ",");
                                                    for (int j = 0; j < 2 && j < xyParsed.length; j++)
                                                            temp[lenOld + i][j] = Double
                                                                            .parseDouble(xyParsed[j]);
                                            }
                                            mRoad.mRoute = temp;
                                    }
                            }
                    }
            }
            mCurrentElement.pop();
            if (localName.equalsIgnoreCase("Placemark")) {
                    isPlacemark = false;
                    if (isRoute)
                            isRoute = false;
            } else if (localName.equalsIgnoreCase("ItemIcon")) {
                    if (isItemIcon)
                            isItemIcon = false;
            }


        return value;
    }

    public Point[] addPoint(Point[] Points) {
            Point[] result = new Point[Points.length + 1];
            for (int i = 0; i < Points.length; i++)
            {  result[i] = Points[i];}
            result[Points.length] = new Point();
            return result;
    }
4

1 に答える 1

1

このリンクを参照して、アプリケーションで駆動パスを描画してください。プロジェクトのリンクにある 4 つのクラスを追加し、ルートを表示する必要がある場合は以下の行を呼び出すだけです。

SharedData data = SharedData.getInstance();
data.setAPIKEY("0RUTLH7cqd6yrZ0FdS0NfQMO3lioiCbnH-BpNQQ");//set your map key here
data.setSrc_lat(17);//set your src lat
data.setSrc_lng(78);//set your src lng
data.setDest_lat(18);//set your dest lat
data.setDest_lng(77);//set your dest lng
startActivity(new Intent(YourActivity.this,RoutePath.class));//add RoutePath in your manifeast file

// マニフェスト ファイルにもアクセス許可を追加します

于 2012-04-26T16:59:15.710 に答える