开发者

JavaScriptInterface() is not working in android

i have written android code and map(html) code by referring this link http://code.google.com/intl/en/apis/maps/articles/android_v3.html#why

i got out put for the same code, but when i changed the html code like this,

HERE IS MY HTML Code

<!DOCTYPE html>
 <html>
<head> 
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/> 
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
<title>Google Maps JavaScript API v3 Example: Directions Simple</title> 
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" /> 
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
<script type="text/javascript"> 

var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var map;

function initialize() {
    directionsDisplay = new google.maps.DirectionsRenderer();
    var chicago = new google.maps.LatLng(41.850033, -87.6500523);
    var myOptions = {
      zoom:7,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      center: chicago
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    directionsDisplay.setMap(map);
}

function calcRoute() {
    var start ;
    var end ;
    if (window.android){
      start= window.android.getsource();
     end = window.android.getdestination();
    }
    var request = {
        origin:start, 
        destination:end,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
    };
    directionsService.route(request, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
        directionsDisplay.setDirections(response);
    }
 });
}
</script> 
</head> 
<body onload="initialize()"> 
<div> 
<input id="latlng" type="textbox" value="Chicago"> 
<input id="latlng1" type="textbox" value="Kingman">
</div> 
<div> 
<input type="button" value="Get Route" onclick="calcRoute()"> 
</div> 

<div id="map_canvas"></div> 
</body> 
</html>

HERE IS MY ANDROID Code

package com.example.test;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;

import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class tset extends Activity {
private static final String MAP_URL = "http://192.168.1.119:81/fulfed1.html";
  private WebView webView;

     public static String disp;
  @Override
  /** Called when the activity is first created. */
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);



    webView = (WebView) findViewById(R.id.webview);
    webView.getSettings().setJavaScriptEnabled(true);
    //Wait for the page to load then send the location information
    webView.setWe开发者_运维知识库bViewClient(new WebViewClient());
    webView.loadUrl(MAP_URL);
    /** Allows JavaScript calls to access application resources **/
    webView.addJavascriptInterface(new JavaScriptInterface(), "android");
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  }
  /** Sets up the WebView object and loads the URL of the page **/
  public class JavaScriptInterface
  {
    public String getsource(){
        return "Washington";
    }
    public String getdestination(){
        return  "Newyork";
    }
    }
  }

i am not getting route direction upon click on "Get route" button in my html code,please help what's wrong in my code.


Maybe you should stick an alert in your response handler function in directionsService.route to see what Google Maps is returning?

My guess is that "Washington" and "Newyork" aren't specific enough to resolve for Google Maps.

If I enter those terms in the Google Maps Directions web page, besides asking me to clarify which 'Washington' and which 'Newyork' I mean (I didn't select anything from the two dropdowns and 'let it ride'), the results that came back were a column titled "Did you mean?" and a list of "Newyork" places.


I found the answer, actually i have converted ascii to string....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜