谷歌地图标记问题

时间:2016-11-13 23:51:06

标签: android google-maps

我试图让地图标记移动。但标记甚至都没有出现。在使用我的JSON对象初始化之后,标记应该正在移动。我的JSON代码在后台每两秒更新一次。也许我正在对待我的JSON对象。

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private LocationManager locationManager;

private GoogleMap mMap;

JSONParser jsonparser = new JSONParser();
private CameraPosition cameraPosition;
private GoogleMap googleMap;



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(map);
    List<MarkerOptions> markerOptions = new ArrayList<>();


    Bitmap.Config conf = Bitmap.Config.ARGB_8888;
    Bitmap bmp = Bitmap.createBitmap(200, 50, conf);
    Canvas canvas = new Canvas(bmp);


    mapFragment.getMapAsync(this);


}


/**
 * nnnnnnnnnnn
 * Manipulates the map once available.
 * This callback is triggered when the map is ready to be used.
 * This is where we can add markers or lines, add listeners or move the camera. In this case,
 * we just add a marker near Sydney, Australia.
 * If Google Play services is not installed on the device, the user will be prompted to install
 * it inside the SupportMapFragment. This method will only be triggered once the user has
 * installed Google Play services and returned to the app.
 */
@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
}


private void setUpMap() {
}


class MarkerTask extends AsyncTask<Void, Void, String> {

    private static final String LOG_TAG = "ExampleApp";

    private static final String SERVICE_URL = "http://api.wheretheiss.at/v1/satellites/25544";

    // Invoked by execute() method of this object
    @Override
    protected String doInBackground(Void... args) {

        HttpURLConnection conn = null;
        final StringBuilder json = new StringBuilder();
        try {
            // Connect to the web service
            URL url = new URL(SERVICE_URL);
            conn = (HttpURLConnection) url.openConnection();
            InputStreamReader in = new InputStreamReader(conn.getInputStream());

            // Read the JSON data into the StringBuilder
            int read;
            char[] buff = new char[1024];
            while ((read = in.read(buff)) != -1) {
                json.append(buff, 0, read);
            }
        } catch (IOException e) {
            Log.e(LOG_TAG, "Error connecting to service", e);
            //throw new IOException("Error connecting to service", e); //uncaught
        } finally {
            if (conn != null) {
                conn.disconnect();
            }
        }

        return json.toString();
    }

    // Executed after the complete execution of doInBackground() method
    @Override
    protected void onPostExecute(String json) {
        JSONParser jsonparser = new JSONParser();
        try {
            // De-serialize the JSON string into an array of city objects

            while (!isCancelled()) {
                JSONObject jsonObj = jsonparser.makeHttpRequest("http://api.wheretheiss.at/v1/satellites/25544");
                ;

                LatLng latLng = new LatLng(jobj.getDouble("longitude"),
                        jobj.getDouble("latitude"));

                //move CameraPosition on first result

                CameraPosition cameraPosition = new CameraPosition.Builder()
                        .target(latLng).zoom(13).build();

                mMap.animateCamera(CameraUpdateFactory
                        .newCameraPosition(cameraPosition));


                // Create a marker for each city in the JSON data.
                mMap.addMarker(new MarkerOptions()
                        .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE))
                        .title("International Space Station")
                        .snippet(Integer.toString(jsonObj.getInt("population")))
                        .position(latLng));


            }
        } catch (JSONException e) {
            Log.e(LOG_TAG, "Error processing JSON", e);
        }

    }
}

}

0 个答案:

没有答案
相关问题