这是我调用GPS坐标的方法。它使用GUI上的按钮onclick工作得很好。但是,每当我尝试从其他方法调用它,它会使我的应用程序崩溃。无法从其他方法调用此方法
public void getPattern(View v){
String s = "http://maps.google.com/maps?f=q&hl=en&q=05.445560,100.424200&ie=UTF8&z=16&iwIoc=addr&om=1speed:000.0&imei=355689019472548";
// String s = messageBox.getText().toString();
// Log.d("check", s);
Pattern p = Pattern.compile("\\d+\\.\\d+");
Matcher m = p.matcher(s);
int i =0;
Float n[] = new Float[4];
while (m.find()) {
System.out.println(m.group());
n[i]= Float.parseFloat(m.group());
i++;
}
LatLng locLatLng = new LatLng(n[0],n[1]);
CameraPosition cameraPosition = new CameraPosition.Builder().target(locLatLng).zoom(15).build();
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
MarkerOptions marker = new MarkerOptions().position(locLatLng).title("Here's your car dude!!!").snippet("Found it!!");
marker.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
googleMap.addMarker(marker).showInfoWindow();
}
迄今为止从LatLng开始的错误。如果我删除了这段代码,当然还有(视图v)和主要方法的调用,如getPattern();
它工作的很好,但我需要LatLng代码的其余部分,以便它可以自动从提取的Lat长度的字符串s中获取位置。 n变量正确捕获经纬度数据。
我的意思是我想从代码中调用这个方法,如在onCreate或其他地方没有与按钮或任何GUI元素交互。例如我有这种方法
public static void updateMessageBox(String msg) {
messageBox.setText(msg);
getPattern();
}
这导致我的应用程序崩溃。如果我开始卸下LatLng
代码它工作得很好,也拆除(View v)
显示在您试图调用这个函数 –
updatemessagebox方法调用getPattern method..I功能发现错误,但未能解决it..the罪魁祸首是一个String,我使用。我无法使用GUI的任何变量输入。我只能在方法中使用静态变量define。 – slumberj