2011-02-01 12 views
0

如何編寫使用谷歌地圖Javascript API第3服務的機器人程序編寫一個程序,我使用的Eclipse ...如何使用谷歌地圖的JavaScript apiv3

http://code.google.com/apis/maps/documentation/javascript/services.html#Directions

從上面的鏈接,我有因爲我想嘗試方向的例子,但他們已經在那裏使用了一些html代碼,但是我必須在我的eclipse的新項目中編寫html腳本代碼,以及以後應該如何鏈接html和android代碼..

我有也看到有人說我們需要在我們的代碼中包含http://maps.google.com/maps/api/js?sensor=false腳本..如何包含t他..?

請給我建議,在此先感謝..

回答

0

加載網頁到Android應用程序是使用的WebView完成。因此,您可能會使用它在原生Android應用程序中加載Maps API網站。 How To.

+0

您好感謝,我已經通過該網站有他們使用一些Java腳本獲得網站的功能,但走了我應該在哪裏,我的Eclipse Java項目.. – manju 2011-02-02 05:49:00

0

請嘗試下面的代碼。這對我來說可以。

//First add permission in manifest file: 
<uses-permission android:name="android.permission.INTERNET"/> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 



public class webViewes extends Activity { 
private static String PROVIDER="gps"; 
private WebView browser; 
private LocationManager myLocationManager=null; 

@Override 
public void onCreate(Bundle icicle) { 
    super.onCreate(icicle); 
    setContentView(R.layout.main); 
    browser=(WebView)findViewById(R.id.webview); 
    myLocationManager=(LocationManager)getSystemService(Context.LOCATION_SERVICE); 
    browser.getSettings().setJavaScriptEnabled(true); 
    browser.addJavascriptInterface(new Locater(), "locater");  
    browser.loadUrl("http://gmaps-samples.googlecode.com/svn/trunk/articles-android-webmap/simple-android-map.html"); 
} 

@Override 
public void onResume() { 
    super.onResume(); 
    myLocationManager.requestLocationUpdates(PROVIDER, 0, 0, onLocation); 
} 

@Override 
public void onPause() { 
    super.onPause(); 
    myLocationManager.removeUpdates(onLocation); 
} 

LocationListener onLocation=new LocationListener() { 
    public void onLocationChanged(Location location) { 
    StringBuilder buf=new StringBuilder("javascript:whereami("); 

    buf.append(String.valueOf(location.getLatitude())); 
    buf.append(","); 
    buf.append(String.valueOf(location.getLongitude())); 
    buf.append(")"); 

    browser.loadUrl(buf.toString()); 
    } 

    public void onProviderDisabled(String provider) { 
    } 
    public void onProviderEnabled(String provider) { 
    } 
    public void onStatusChanged(String provider, int status,Bundle extras) { 
    } 
}; 

public class Locater { 
    public String getLocation() throws JSONException { 
    Location loc=myLocationManager.getLastKnownLocation(PROVIDER); 

    if (loc==null) { 
     return(null); 
    } 

    JSONObject json=new JSONObject(); 

    json.put("lat", loc.getLatitude()); 
    json.put("lon", loc.getLongitude()); 

    return(json.toString()); 
    } 
} 

}