2
我正在与一个iOS应用程序codename one。我想获取当前位置并通过短信发送。Codename一个GPS提供商和当前位置
我从Java Android Studio得到了这段代码,我不知道如何获取当前位置并检查GPS是否打开。
我试过以下,但没有成功(我不知道他们是如何启动GPS,并获得位置)
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
boolean enabledGPS = service.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (!enabledGPS) {
//alert GPS is off
}
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// Define the criteria how to select the location provider -> use
// default
Criteria criteria = new Criteria();
provider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(provider);
// Initialize the location fields
if (location != null) {
Toast.makeText(this, "Provider: " + provider, Toast.LENGTH_SHORT).show();
onLocationChanged(location);
} else {
//do something
}
的onLocationChanged方法:
try {
StringBuffer smsBody = new StringBuffer();
smsBody.append("http://maps.google.com/?q=");
smsBody.append(gpsLocation.getLatitude());
smsBody.append(",");
smsBody.append(gpsLocation.getLongitude());
String phnum="xxxxx";
String smsbod= smsBody.toString();
Display.getInstance().sendSMS(phnum,smsbod);
} catch (IOException ex) {
Dialog.show("Error!", "Failed to start. installed?", "OK", null);
ex.printStackTrace();
}
在这个时候,我不接受错误,但没有happend。不是短信发送,而不是对话框警告。我打开GPS –
在哪个设备上试用?尝试更改此Display.getInstance()。sendSMS(“09123456789”,“http://maps.google.com/?q=”+ lat +“,”+ lng,false);'Display this.getInstance ().sendSMS(“09123456789”,“http://maps.google.com/?q=”+ lat +“,”+ lng,true);' – Diamond
我正在使用三星Xcover 2(android)应用程序它应该在IOS上工作,但我认为我可以在任何设备上先测试它 –