我将在谷歌地图v2上显示多个位置的Android应用程序,该点已存储在sqlte数据库中。但现在,我面临一些没有显示任何位置的问题。也没有任何错误。怎么了?
我的代码
地图活动课
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import com.example.location_application_v1.R;
import com.google.android.gms.internal.gs;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class AllMap extends Activity {
ArrayList<GS> q = new ArrayList<GS>();
private GoogleMap googleMap;
String name;
double lat;
double lang;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_all_map);
try {
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
DBAdapter db = DBAdapter.getDBAdapter(getApplicationContext());
db.openDatabase();
db.GetAllPin();
for (int i = 0; i < q.size(); i++) {
Log.i("arr", "" + q.get(i).getId());
// lat=db.GetAllPin().get(i).getLat();
// lang=db.GetAllPin().get(i).getLng();
lat = q.get(i).getLat();
lang = q.get(i).getLng();
LatLng latlng = new LatLng(lat, lang);
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map1)).getMap();
googleMap.addMarker(new MarkerOptions().position(
new LatLng(lat, lang)).title(q.get(i).getName()));
}
}
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map1)).getMap();
googleMap.addMarker(new MarkerOptions().position(new LatLng(lat,
lang)));
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
@Override
protected void onResume() {
super.onResume();
initilizeMap();
}
}
答案 0 :(得分:0)
我认为你需要改变:
db.GetAllPin();
到
q = db.GetAllPin();
您已初始化q
,但您没有为此设置任何内容,因为GetAllPin
返回ArrayList<GS>
我认为您已忘记将其设置为q
,如下所示您尝试使用以下代码进行q
行:
for (int i = 0; i < q.size(); i++)