谷歌地图准确性问题

时间:2013-03-07 22:03:50

标签: java android api google-maps

我有一个谷歌地图应用程序,可以抓取用户的lat和long值,并通过使用Google JSON响应存储一系列超市对象及其相对纬度和长值。我使用覆盖类将标记放置到地图上,这取决于列表视图中显示可用超市的所选超市。

这一切都很好,我似乎有一个轻微的问题是我的覆盖类的准确性。地图标记似乎不是非常准确,因为标记指向指定纬度的错误位置以及从我的geopoint对象传递给它的长点。 (有时距离应该的地方最远11英里)。

我已尝试在使用权限中声明清单中的LOCATION_FINE,但这似乎没有任何区别。我是否需要这个,因为我使用的是JSON响应而不是GPS?

模拟器上的地图有多准确?我可能会抓住吸管,但我听到有很多人说在模拟器上使用Google API时并不准确。

没有使用GPS。

修改

添加到此问题。我有另一个更深入的问题。我认为问题出在我的update()方法中,因为问题是错误的对象lat和长值被发送到标记。

我会发布我的代码,只是为了看看是否有人可以找到任何问题。

GeoName类:

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;
    }   
}
}

2 个答案:

答案 0 :(得分:3)

管理对此进行排序。

对于使用JSON分层响应的任何其他人。确保从正确的GeoPoint对象类中访问lat和long值。

答案 1 :(得分:2)

为简单起见,您可以使用Google Maps Android API v2进行最新更新,您的任务变得更加简单。 https://developers.google.com/maps/documentation/android/start

您只需要创建GoogleMap对象并添加适当的侦听器。

相关问题