1

googlemapからKMLファイルを取得する必要があります。返却しませんでした。これは、KMLを取得するための私のコードです。

  public String[] getPathString(String saddr, String daddr){
     String [] result = {"",""};
      try {

        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpGet getRequest = new HttpGet(
            "http://maps.google.com/maps?f=d&hl=en&saddr="+saddr+"&daddr="+daddr+"&ie=UTF8&0&om=0&z=20&output=kml");
        getRequest.addHeader("accept", "application/json");

        HttpResponse response = httpClient.execute(getRequest);

        if (response.getStatusLine().getStatusCode() != 200) {
            throw new RuntimeException("Failed : HTTP error code : "
               + response.getStatusLine().getStatusCode());
        }

        BufferedReader br = new BufferedReader(
                         new InputStreamReader((response.getEntity().getContent())));

        String output;
        StringBuilder urlString = new StringBuilder();
        System.out.println("Output from Server .... \n");
        while ((output = br.readLine()) != null) {
            System.out.println(output);
            urlString.append(output);
            urlString.append("\n");
        }
        System.out.println(urlString);


        String coordinatestring  = urlString.toString().split("<LineString>")[1].split("<coordinates>")[1].split("</coordinates>")[0];
        //System.out.println(coordinatestring);
        String []  coordinates = coordinatestring.split(",0.000000 ");
        //String lineString = "LINESTRING(";
        String lineString =  "";
        for (int i = 0; i < coordinates.length-1; i++){
            lineString += coordinates[i].replace(',', ' ')+",";
        }
        if (lineString.length() > 0)
        lineString = lineString.substring(0,lineString.length()-1);
        //lineString += ")";
        //   );
        System.out.println(lineString);
        result [0] = lineString;

        String ditanceString = "";
        if (urlString.toString().length() > 200)
        ditanceString = urlString.toString().split("Distance:")[1].split("&#")[0];

        result[1]  = ditanceString;


        httpClient.getConnectionManager().shutdown();
        //return result;

      } catch (ClientProtocolException e) {

        e.printStackTrace();

      } catch (IOException e) {

        e.printStackTrace();
      }

      return result; 
    }

これはサンプルURLです:http: //maps.google.com/maps?f = d&hl = en&saddr = 6.87988,79.8906&daddr = 6.87991,79.8911&ie = UTF8&0&om = 0&z = 20&output = kml

しかし、これは次のようになります。

    </script> <script type="text/javascript">window.onunload = function(){GUnload();};</script> <script type="text/javascript">window.onresize = function(){resizeApp();};</script>     <style>.msie
e('inlineMarkersContainer').style.display = 'block';function constructEventQueue(queue,handler){return {q:queue,h:handler
}
}
function addDocListener(eventName,fn){if (document.addEventListener){document.addEventListener(eventName,fn,false);}else if (document.attachEvent){document.attachEvent("on" + eventName,fn);}


}
function removeDocListener(eventName,fn){if (document.removeEventListener){document.removeEventListener(eventName,fn,false);}else if (document.detachEvent){document.detachEvent("on" + eventName,fn);}


}





window.gEventQueue = (function(){





function getJsactionNodeForQueuing_(e){var node = e.srcElement || e.target;
if (node.nodeType == 3)node = node.parentNode;


var isMac = /Macintosh/.test(navigator.userAgent);var modified = (isMac && e.metaKey ||
!isMac && e.ctrlKey);
var re = modified ?/^click(modified)?:/ :
/^[^:]*$|^click(plain)?:/;



while (node){var attr = (node.getAttribute &&
node.getAttribute('jsaction'));if (attr){for (var i = 0,actions = attr.split(';');i < actions.length;i++){if (re.test(actions[i])){return node;}
}
}
node = node.parentNode;}
return null;}


var queue = [];

function handler(e){var node = getJsactionNodeForQueuing_(e);if (!node)return;

e.replayTimeStamp = (new Date).getTime();
e.stopPropagation ?e.stopPropagation():(e.cancelBubble = true);
if (node.tagName == 'A' && e.type == 'click'){e.preventDefault ?e.preventDefault():(e.returnValue = false);}

var copy = {};for (var i in e){copy[i]= e[i];}
queue.push(copy);}

addDocListener('click',handler);

return constructEventQueue(queue,handler);}());(function(){var init_timeout=5000;setTimeout(function(){
vpLoad.arg(0,'ait').check();},init_timeout);})();(function(){var main_js_before_onload=true;var not_fully_inlined=true;window.jsLoadCallback = function(appOptions){vpLoad.arg(3,appOptions).check();if (main_js_before_onload){


vpLoad.arg(0,'aij1').check();}
if (not_fully_inlined){

..................


gEventQueue = null;}
function onLoadHideLoadMessage(){}
function onLoadMainJs(){}
function onLoadApplicationInitialize(){
vpLoad.arg(0,'aiol').check();}
function onLoad(){onLoadHideLoadMessage();onLoadMainJs();onLoadApplicationInitialize();}

vpLoad.func(function(sourceTick,vPage,stateBox,appOptions,isHomeVPage){
vpLoad.func(null);loadApplication(vPage,stateBox,appOptions,isHomeVPage);}).check();window.onload = onLoad;

var userActions = [
'mousedown','keydown','mousewheel',
'DOMMouseScroll' 
];var gUserAction = false;function firstActionLoadMessages(){}
function firstActionLoadApplication(){setTimeout(function(){vpLoad.arg(0,'aiua').check();},0);}
function onFirstUserAction(event){for (var i = 0;i < userActions.length;++i){removeDocListener(userActions[i],onFirstUserAction);}
if (gUserAction)return;gUserAction = true;firstActionLoadMessages();firstActionLoadApplication();}

for (var i = 0;i < userActions.length;++i){addDocListener(userActions[i],onFirstUserAction);}
(function(){var cityblock_enabled=true;

if (navigator.geolocation){var inline_compass_size = 90;

var zoomTop = 29 + inline_compass_size;var zoomHeight = 377;e('flmc_inline').style.height = '' + zoomHeight + 'px';e('flmczoom_inline').style.top = '' + zoomTop + 'px';if (cityblock_enabled){
var cbTop = 27 + inline_compass_size;var cbTopPx = '' + cbTop + 'px';var launchpad = e('cb_inl_launchpad');if (launchpad){launchpad.style.top = cbTopPx;}



var pegman = e('pegman_inline');if (pegman){pegman.style.top = cbTopPx;}
}

d1('my_location_button');}
})();</script>  <div></div>  </body> </html>

誰かが私に問題が何であるかを助けてください?

前もって感謝します。

4

1 に答える 1

1

KML ファイルを解析して Google から Google のルート案内を抽出するこの方法は、2012 年 7 月 27 日以降利用できなくなりました (Google が Google のルート案内を取得する構造を変更したため、現在は JSON または XML でのみ取得できます)。

于 2012-08-21T09:53:21.350 に答える