我下面的实现方法肯定是错误的,不知道如何将高德地图fragment添加到UZWebView中的,能否帮给我指点一下。
package com.abc.amap;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.RelativeLayout;
import com.uzmap.pkg.uzcore.UZWebView;
import com.uzmap.pkg.uzcore.uzmodule.UZModule;
import com.uzmap.pkg.uzcore.uzmodule.UZModuleContext;
/**
* 该类映射至Javascript中moduleDemo对象
* Js Example:
* var module = api.require('moduleDemo');
* module.xxx();
* @author APICloud
*
*/
public class OtanAMapModule extends UZModule {
private AmapFragment amapFragment = null;
public OtanAMapModule(UZWebView webView) {
super(webView);
}
/**
* 获得地图中心点
* @param moduleContext
*/
public void jsmethod_getMapCenter(final UZModuleContext moduleContext){
JSONObject ret = new JSONObject();
try {
ret.put("lat",AmapFragment.getCenter().latitude);
ret.put("lng",AmapFragment.getCenter().longitude);
} catch (JSONException e) {
e.printStackTrace();
}
moduleContext.success(ret, true);
}
/**
* 打开高德地图
* @param moduleContext
*/
public void jsmethod_open(final UZModuleContext moduleContext)
{
//(1)获得要显示的高德地图窗口位置
int x = moduleContext.optInt("x");
int y = moduleContext.optInt("y");
int w = moduleContext.optInt("w");
int h = moduleContext.optInt("h");
if(w == 0){
w = ViewGroup.LayoutParams.MATCH_PARENT;
}
if(h == 0){
h = ViewGroup.LayoutParams.MATCH_PARENT;
}
//(3)构造mapView显示的布局
ViewGroup.MarginLayoutParams marginLayoutParams =new ViewGroup.MarginLayoutParams(w,h);
marginLayoutParams.setMargins(x,y,0,0);
//(5) 获得当前的Activity
Activ