我如何从 sqlite 数据库查询纬度/经度值并显示在 Google 地图上
如何从数据库查询纬度/经度值并在该位置显示标记? 这是我的代码,当我设置纬度/经度时它工作正常
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.branchmap);
mapView = (MapView) findViewById(R.id.mapView1);
mc = mapView.getController();
String[] coordinates = {"13.694317","100.601592"};
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
p = new GeoPoint(
(int) (lat * 1E6),
(int) (lng * 1E6));
mc.animateTo(p);
mc.setZoom(17);
mapOverlays = mapView.getOverlays();
drawable = this.getResources().getDrawable(R.drawable.mark1);
itemizedOverlay = new HelloItemizedOverlay(drawable);
OverlayItem overlayitem = new OverlayItem(p, "", "");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
,但是当我想查询它时它不起作用,我应该把这部分代码放在哪里
try {
ChannelDatabaseHelper dbHelper = new ChannelDatabaseHelper(this.getApplicationContext());
newDB = dbHelper.getWritableDatabase();
Cursor c1 = newDB.rawQuery("SELECT lat,long FROM " +
tableName , null);
if (c1 != null ) {
if (c1.moveToFirst()) {
do {
latitude =Integer.parseInt((c1.getString(c1.getColumnIndex("lat"))));
longitude = Integer.parseInt((c1.getString(c1.getColumnIndex("long"))));
p = new GeoPoint(
(int)(latitude *1E6 ),
(int)(longitude *1E6 ));
}while (c1.moveToNext());
}
}
How can i query lat/long value from database and display the marker on that location?
this is my code, it works fine when i set lat/long
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.branchmap);
mapView = (MapView) findViewById(R.id.mapView1);
mc = mapView.getController();
String[] coordinates = {"13.694317","100.601592"};
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
p = new GeoPoint(
(int) (lat * 1E6),
(int) (lng * 1E6));
mc.animateTo(p);
mc.setZoom(17);
mapOverlays = mapView.getOverlays();
drawable = this.getResources().getDrawable(R.drawable.mark1);
itemizedOverlay = new HelloItemizedOverlay(drawable);
OverlayItem overlayitem = new OverlayItem(p, "", "");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
but when i want to query it doesn't work, where should i put this part of code
try {
ChannelDatabaseHelper dbHelper = new ChannelDatabaseHelper(this.getApplicationContext());
newDB = dbHelper.getWritableDatabase();
Cursor c1 = newDB.rawQuery("SELECT lat,long FROM " +
tableName , null);
if (c1 != null ) {
if (c1.moveToFirst()) {
do {
latitude =Integer.parseInt((c1.getString(c1.getColumnIndex("lat"))));
longitude = Integer.parseInt((c1.getString(c1.getColumnIndex("long"))));
p = new GeoPoint(
(int)(latitude *1E6 ),
(int)(longitude *1E6 ));
}while (c1.moveToNext());
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个代码
Try this code