Google maps accuracy issue
android, api, google-maps, java
Solution
Managed to sort this.
For anyone else who is using a JSON layered response. Make sure you access you lat and long values from the correct GeoPoint object classes.
Problem
I have a Google maps app that grabs the users lat and long values, and through the use of a Google JSON response stores a range of supermarket objects with their relative lat and long values. I use an overlay class to the place a marker onto the map dependent on the selected supermarket from the listview that shows the available supermarkets. This all works fine, where I seem to be having a slight issue is with the accuracy of my overlay class. The map marker doesn't seem to be very accurate, in that the marker is pointing at the wrong place of the specified lat and long points passed to it from my geopoint object. (sometimes up to 11 miles away from where it should be). I have tried declaring the LOCATION_FINE in my manifest on the uses permissions but this doesn't seem to make any difference. Do I need this as I'm using a JSON response rather than GPS? How accurate is the map on the emulator? I may-be clutching at straws here but I have heard multiple people saying that when using the Google API's on the emulator it isn't that accurate. No GPS is being used. EDIT To add to this question. I have another question that goes into more depth. I believe the issue is within my update() method as the issue is the incorrect object lat and long values are being sent to the marker. I will post my code, just to see if anyone can find any issues. GeoName class: ``` 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 class: ``` 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; } } } ```