|
/**
* 获取当前位置
*
* @param moduleContext
* @return
*/
@UzJavascriptMethod
public void jsmethod_currentLocation(final UZModuleContext moduleContext) {
CommonUtil.showToast("获取当前位置");
final Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
int what = msg.what;
switch (what) {
case OK:
Location location = CareService.mLocation;
JSONObject result = new JSONObject();
String loc = location.getLongitude() + ","
+ location.getLatitude();
try {
result.put("location", loc);
} catch (JSONException e) {
e.printStackTrace();
}
moduleContext.success(result, false);
break;
case FAIL:
moduleContext.error(null, null, true);
break;
}
}
};
new Thread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < 10; i++) {
Location location = CareService.mLocation;
if (location == null) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
} else {
handler.sendEmptyMessage(OK);
break;
}
if (i == 9) {
handler.sendEmptyMessage(FAIL);
}
}
}
}).start();
}
这是模块中一个方法 |
|