Adding Multiple Markers in real time google maps v2 android

awaistoor

I want to add markers when ever on camera change listener is called.

@Override
public void onCameraChange(CameraPosition position) {
    // TODO Auto-generated method stub
    double[] newValues = { position.target.latitude,
            position.target.longitude };
    new GetPlaces().execute(newValues);
}

AsyncTask Class which is used to get the center location of the map and get known places arround that location

private class GetPlaces extends AsyncTask<double[], Void, Boolean> {

    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        super.onPreExecute();

    }

    @Override
    protected Boolean doInBackground(double[]... params) {
        // TODO Auto-generated method stub
        double[] vals = params[0];
        HttpRequest request = new HttpRequest();
        try {
            locs = request.getPlaces(vals[0], vals[1]);
            return true;
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return false;
        }

    }

    @Override
    protected void onPostExecute(Boolean result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);

        if (result) {
                if (mMap != null) {
            if (locs.size() > 0) {


                    mMap.clear();

                    for (com.matsoltech.android.apps.easysavinghunter.Location loc : locs) {

                        Log.e("APPLICATION", "LOCATIONS FOUND ");
                        mMap.addMarker(new MarkerOptions()
                                .position(
                                        new LatLng(loc.getPoint()
                                                .getLatitude(), loc
                                                .getPoint().getLongitude()))
                                .title(loc.getName())
                                .icon(BitmapDescriptorFactory
                                        .defaultMarker(BitmapDescriptorFactory.HUE_RED)));
                    }

                } else {
                    Toast.makeText(MainActivity.this, "No Deal Found",
                            Toast.LENGTH_LONG).show();
                }
            } else {
                Log.e("APPLICATION", "MAP IS NULL");
            }
        } else {
            Toast.makeText(
                    MainActivity.this,
                    "Oops..Something went wrong. Please check your connection and try again",
                    Toast.LENGTH_LONG).show();
        }
    }
}

In logcat the values are correct and data is being fetched properly .. the only problem is that my markers are not showing on the map. Please help!!

awaistoor

The answer is that i wasn't putting the right values of Lat and Lng in the Point object. Now its working find!!

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

android maps api v2 adding multiple circles

分類Dev

How to manage Markers well using google maps api v2 on android

分類Dev

Google Maps Android API v2

分類Dev

Google map API v2 Android - Markers & scale

分類Dev

Google Maps Android API v2 Authorization failure

分類Dev

Can't connect to Google Maps Api Android V2

分類Dev

Overlay an image on google maps android api v2

分類Dev

Google Maps Activity V2 Android Studio

分類Dev

displaying Google Maps API v2 on real device/emulator. can't figure out error

分類Dev

Google Map API V3 - infowindows @ markers on 2 maps

分類Dev

How to Add Google Maps with Multiple Markers Showing Infowindows on Load and on Click

分類Dev

How to hide/show groups of markers by category with Google Maps in Android?

分類Dev

Android 2.3およびgoogle maps API v2

分類Dev

Circle on Google Maps for Android v2 is flickering when size changes by seekbar

分類Dev

Android Google Maps API v2:方位位置を取得する

分類Dev

How to animate the camera to a specified location in Google Maps v2 for Android?

分類Dev

Android google maps v2 execute asynctask when user stops moving the camera

分類Dev

How to clear Google map v2 except few markers?

分類Dev

ReactJS and Google Maps - Displaying Markers

分類Dev

Google android maps api v2マーカータイトルを常に表示

分類Dev

Animated Transparent Circle on Google Maps v2 is NOT animating correctly

分類Dev

How to set api key for Google maps v2

分類Dev

Google maps v2 not displayed on new activity

分類Dev

Google Maps V2 - API key not found Error Message

分類Dev

Draw circles around multiple markers in Maps

分類Dev

Placing Circles instead of Markers in google maps

分類Dev

Google maps delete all markers and then create new

分類Dev

Google Maps: infobox turns up behind markers?

分類Dev

Google Maps fit markers in custom bounds

Related 関連記事

  1. 1

    android maps api v2 adding multiple circles

  2. 2

    How to manage Markers well using google maps api v2 on android

  3. 3

    Google Maps Android API v2

  4. 4

    Google map API v2 Android - Markers & scale

  5. 5

    Google Maps Android API v2 Authorization failure

  6. 6

    Can't connect to Google Maps Api Android V2

  7. 7

    Overlay an image on google maps android api v2

  8. 8

    Google Maps Activity V2 Android Studio

  9. 9

    displaying Google Maps API v2 on real device/emulator. can't figure out error

  10. 10

    Google Map API V3 - infowindows @ markers on 2 maps

  11. 11

    How to Add Google Maps with Multiple Markers Showing Infowindows on Load and on Click

  12. 12

    How to hide/show groups of markers by category with Google Maps in Android?

  13. 13

    Android 2.3およびgoogle maps API v2

  14. 14

    Circle on Google Maps for Android v2 is flickering when size changes by seekbar

  15. 15

    Android Google Maps API v2:方位位置を取得する

  16. 16

    How to animate the camera to a specified location in Google Maps v2 for Android?

  17. 17

    Android google maps v2 execute asynctask when user stops moving the camera

  18. 18

    How to clear Google map v2 except few markers?

  19. 19

    ReactJS and Google Maps - Displaying Markers

  20. 20

    Google android maps api v2マーカータイトルを常に表示

  21. 21

    Animated Transparent Circle on Google Maps v2 is NOT animating correctly

  22. 22

    How to set api key for Google maps v2

  23. 23

    Google maps v2 not displayed on new activity

  24. 24

    Google Maps V2 - API key not found Error Message

  25. 25

    Draw circles around multiple markers in Maps

  26. 26

    Placing Circles instead of Markers in google maps

  27. 27

    Google maps delete all markers and then create new

  28. 28

    Google Maps: infobox turns up behind markers?

  29. 29

    Google Maps fit markers in custom bounds

ホットタグ

アーカイブ