我有一个谷歌地图应用程序,它可以获取用户的纬度和经度值,并通过使用谷歌 JSON 响应存储一系列超市对象及其相对经度和经度值。我使用覆盖类在地图上放置一个标记,该标记取决于从显示可用超市的列表视图中选择的超市。
这一切都很好,我似乎有一个小问题是我的覆盖类的准确性。地图标记似乎不是很准确,因为标记指向从我的地理点对象传递给它的指定纬度和经度点的错误位置。(有时距离它应该在的地方最多 11 英里)。
我已经尝试在我的清单中声明 LOCATION_FINE 使用权限,但这似乎没有任何区别。当我使用 JSON 响应而不是 GPS 时,我需要这个吗?
模拟器上的地图有多准确?我可能在这里抓着稻草,但我听到很多人说在模拟器上使用 Google API 时它并不准确。
没有使用 GPS。
编辑
补充这个问题。我还有一个更深入的问题。我相信问题出在我的 update() 方法中,因为问题是不正确的对象 lat 和 long 值被发送到标记。
我将发布我的代码,只是为了看看是否有人能找到任何问题。
地名类:
public class GeoName {
private String id;
private Geometry geometry;
private String name;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Geometry getGeometry() {
return geometry;
}
public void setGeometry(Geometry geometry) {
this.geometry = geometry;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
PostalCodeAdapter 类:
package com.example.restfulweb;
public class PostalCodeAdapter extends BaseAdapter {
private Context ctx = null;
Location l;
Dialog d;
Double Latt;
Double Longg;
private List<GeoName> names = new ArrayList<GeoName>();
public PostalCodeAdapter(Context ctx, List<GeoName> locations) {
this.ctx = ctx;
this.names = locations;
}
@Override
public int getCount() {
return names.size();
}
@Override
public Object getItem(int arg0) {
return null;
}
@Override
public long getItemId(int arg0) {
return 0;
}
@Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
LinearLayout layout = new LinearLayout(ctx);
AbsListView.LayoutParams params = new AbsListView.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT);
layout.setLayoutParams(params);
layout.setOrientation(LinearLayout.HORIZONTAL);
GeoName location = this.names.get(arg0);
Location l = location.getGeometry().getLocation();
Latt = l.getLat();
Longg = l.getLng();
TextView value = new TextView(this.ctx);
value.setText(location.getName());
value.setMaxHeight(100);
value.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
value.setGravity(Gravity.CENTER);
value.setOnClickListener(new CityClickListener(location));
layout.addView(value);
return layout;
}
class CityClickListener implements OnClickListener {
private GeoName geoName = null;
CityClickListener(GeoName name) {
this.geoName = name;
}
@Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
builder.setView(createView());
builder.setTitle("Details of " + geoName.getName());
builder.setCancelable(true);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
updateMap();
}
private void updateMap() {
MapActivity mapAct = (MapActivity)ctx;
MapView map = (MapView)mapAct.findViewById(R.id.map);
map.setScrollBarStyle(MapView.SCROLLBARS_INSIDE_INSET);
map.setBuiltInZoomControls(Boolean.TRUE);
map.displayZoomControls(Boolean.TRUE);
********** ISSUE: THE PASSED LAT AND LONG VALUES ARE NOT BEING PASSED TO THE OVERLAY **********
GeoPoint point = new GeoPoint((int)(Latt* 1E6), (int)(Longg * 1E6));
MapController mc = map.getController();
mc.setZoom(17);
mc.setCenter(point);
mc.animateTo(point);
List<Overlay> overlay = map.getOverlays();
overlay.clear();
Drawable marker = ctx.getResources().getDrawable(R.drawable.marker);
MyItemizedOverlay overlays = new MyItemizedOverlay(marker, map, ctx);
OverlayItem pointerConverted = new OverlayItem(point, geoName.getName(), null);
overlay.add(overlays);
overlays.addOverlay(pointerConverted);
}
private View createView() {
LinearLayout l = new LinearLayout(ctx);
l.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams params = new LayoutParams(100, 300);
l.setLayoutParams(params);
TextView city = new TextView(ctx);
city.setText("Supermarket: " + geoName.getName() + "");
city.setMaxHeight(100);
city.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
city.setGravity(Gravity.CENTER);
//city.setTextColor(ctx.getResources().getColor(R.color.white));
TextView orientation = new TextView(ctx);
//orientation.setText("Orientation : " + geoName.lat + " || " + geoName.lng);
orientation.setMaxHeight(100);
orientation.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
orientation.setGravity(Gravity.CENTER);
l.addView(city);
l.addView(orientation);
return l;
}
}
}