开发者

How to write a program using google map javascript apiv3

开发者 https://www.devze.com 2023-02-08 07:47 出处:网络
How to write an android program using Google Maps Javascript API V3 Services,i am using eclipse... http://code.google.com/apis/maps/documentation/javascript/services.html#Directions

How to write an android program using Google Maps Javascript API V3 Services,i am using eclipse...

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

from the above link which i have given i want to try out direction example but they have used some html code over there,but where i have to write html scripting code in my eclipse's new project and later how should i link html and android code..

i have also seen people saying we need to include http://maps.google.c开发者_如何学JAVAom/maps/api/js?sensor=false script in our code..how to include this ..?

please suggest me ,Thanks in advance..


Loading a web page into an Android application is done using a WebView. So you might use it to load a Maps API site in a Native Android Application. How To.


try below code. it works fine for me.

//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());
  }
}

}

0

精彩评论

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

关注公众号