如何在Android中使用Latitud和Longitud作为变量?
我有一个SQLITE3数据库,我在其中定义了lat和LONGAS text。 我需要使用这些lat,只要是地图上的最终目的地。如何在Android中使用Latitud和Longitud作为变量?,android,google-maps,Android,Google Maps,我有一个SQLITE3数据库,我在其中定义了lat和LONGAS text。 我需要使用这些lat,只要是地图上的最终目的地。 意图定义为: if(locationMap != null){ Intent theIntent = new Intent(getApplication(), displayMap.class); theIntent.putExtra("_Id", locationMap.get("_Id"));
意图定义为:
if(locationMap != null){
Intent theIntent = new Intent(getApplication(), displayMap.class);
theIntent.putExtra("_Id", locationMap.get("_Id"));
theIntent.putExtra("locCode", locationMap.get("locCode"));
theIntent.putExtra("locDesc", locationMap.get("locDesc"));
theIntent.putExtra("locLat", locationMap.get("locLat"));
theIntent.putExtra("locLong", locationMap.get("locLong"));
theIntent.putExtra("locTelephone", locationMap.get("locTelephone"));
theIntent.putExtra("locComments", locationMap.get("locComments"));
startActivity(theIntent); // display map with coordinates
}
在下一个活动中,我将恢复On create方法中的值:
// Parameters
String locCode = i.getStringExtra("locCode");
String locDesc = i.getStringExtra("locDesc");
String locLat = i.getStringExtra("locLat");
String locLong = i.getStringExtra("locLong");
String locTelephone = i.getStringExtra("locTelephone");
String locComments = i.getStringExtra("locComments");
String Text = "Current location is: " +
i.getStringExtra("locLat");
Toast.makeText( getApplicationContext(),Text,
Toast.LENGTH_SHORT).show();
System.out.println("locCode: " + locCode);
System.out.println("LocDesc: " + locDesc);
System.out.println("LocLat: " + locLat);
System.out.println("LocLong: " + locLong);
System.out.println("LocTelephone: " + locTelephone);
System.out.println("LocComment: " + locComments);
getLocation(ORIGIN);
setContentView(R.layout.map);
if (mLastSelectedMarker != null && mLastSelectedMarker.isInfoWindowShown()) {
// Refresh the info window when the info window's content has changed.
mLastSelectedMarker.showInfoWindow();
}
setUpMapIfNeeded();
}
我需要使用那些locLat和Loclong,而不是数字:
public class displayMap extends FragmentActivity implements
OnMarkerClickListener,
OnInfoWindowClickListener {
public LatLng ORIGIN = new LatLng(34.02143074239393, -117.61349469423294);
public LatLng DESTINY = new LatLng(34.022365269080886, -117.61271852999926);
private GoogleMap mMap;
private Marker mDestiny;
private Marker mOrigin;
private Marker mLastSelectedMarker; // keeps track of last selected marker
我试着将文本转换为两倍,但它不允许我这样做
我在堆栈溢出上找到了很多解决方案,但都没有找到
谢谢你的帮助
提前感谢。您需要将纬度和经度从字符串解析为双精度,以便在
new LatLng()中使用代码>
然后呢,
public LatLng ORIGIN = new LatLng(latitude, longitude);
你需要把它们打成两个。正如GPRathour所说。在SQL Lite中将Lat Long文本的类型更改为REAL,
插入值时,请使用
values.put(Latitude_Column, ORIGIN.latitude);
values.put(Longitude__Column,ORIGIN.longitude);
和用于检索值
LatLng origin=新LatLng(cursor.getDouble(cursor.getColumnIndex(纬度列)),cursor.getDouble(cursor.getColumnIndex(经度列))
无需解析值因为您是这里的新用户,请允许我告诉您,如果您获得了问题的解决方案,让其他人知道什么对您有效,您应该在这里接受答案。若要接受答案,只需单击答案左侧的右勾号即可。我做到了。谢谢
values.put(Latitude_Column, ORIGIN.latitude);
values.put(Longitude__Column,ORIGIN.longitude);