-1

I am getting the above error while trying to use MapView in Android to display points on a map using values obtained from reading a JSON structure. The map works perfectly and displays the test points, the values for which I manually set, but it gives the error “failed to find provider info for com.google.settings” when I initialize a string formatted as a JSON structure, then try to read the values from it.

Note: I already have and am using a Google maps API key. I have also set internet permissions. I am able to connect to a website with an HttpGet request and retrieve a JSON structure from there. The map displays properly if I take out the try/catch with the JSON reading code, but gives the aforementioned error otherwise.

Here is the code:

package com.android.google.maps;

import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.LinearLayout;

public class PointMap extends MapActivity {
    /** variables */
    LinearLayout linearLayout;
    MapView mapView;

    List<Overlay> mapOverlays;
    Drawable drawable;
    PointsItemizedOverlay itemizedOverlay;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);

        mapOverlays = mapView.getOverlays();
        drawable = this.getResources().getDrawable(R.drawable.androidmarker);
        itemizedOverlay = new PointsItemizedOverlay(drawable);


        //test points
        GeoPoint point = new GeoPoint(19240000,-99120000);
        OverlayItem overlayitem = new OverlayItem(point, "", "");
        itemizedOverlay.addOverlay(overlayitem);
        GeoPoint point2 = new GeoPoint(35410000, 139460000);
        OverlayItem overlayitem2 = new OverlayItem(point2, "", "");
        itemizedOverlay.addOverlay(overlayitem2);


        String jStringTest = "{\"points\": [{\"id\": 00001,  \"latitude\": 45.721535000000003, \"longitude\": -78.957449999999994}," +
                " {\"id\": 00002,  \"latitude\": 39.722852000000003, \"longitude\": -56.008089999999996}]}";

        try {

        JSONObject jObject = new JSONObject(jStringTest);
        JSONArray pointArray = jObject.getJSONArray("points");

        for (int i = 0; i < pointArray.length(); i++) {
            String pointId = pointArray.getJSONObject(i).getString("id");
            double pointLatitude = pointArray.getJSONObject(i).getDouble("latitude");
            double pointLongitude = pointArray.getJSONObject(i).getDouble("longitude");

            GeoPoint point3 = new GeoPoint((int) (pointLatitude*Math.pow(10, 6)), (int) (pointLongitude*Math.pow(10, 6)));
            OverlayItem overlayitem3 = new OverlayItem(point3, "", "");
            itemizedOverlay.addOverlay(overlayitem3);
        }

        } catch (Exception e) {System.out.println("Exception");};


        mapOverlays.add(itemizedOverlay);
    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }

}
  • @MarvinPinto Yes, and as I stated in the question, not having a maps API key is not the problem - the map works, but for some reason fails and gives the aforementioned error if I put in code to parse a JSON string. – tildeATHcoder Feb 10 '12 at 00:14

1 Answers1

1

Try this

spotLatitude*Math.pow(10, 6) instead use spotLatitude*1E6 .

You didn't mentioned the error exactly . What type of error it . try to post the error message you got in logcat

sudheer
  • 184
  • 1
  • 10
  • The error is in the post title: "failed to find provider info for com.google.settings" Also I tried your suggestion, same result. – tildeATHcoder Feb 06 '12 at 09:15
  • Make sure you gave Internet permissions in manifest file and used maps api key . [Click here](http://stackoverflow.com/questions/1988078/android-failed-to-find-provider-info-for-com-google-settings-in-mapview-exampl) for more details – sudheer Feb 06 '12 at 09:25
  • I have already done this - the map already works, but fails when I put in the JSON code for some reason. – tildeATHcoder Feb 06 '12 at 09:30