Setting ID to google map API v2 marker to return image taken by camera intent

后端 未结 2 810
灰色年华
灰色年华 2021-01-15 23:54

Okay, This problem i have been facing for a couple of days now and can\'t seem to resolve.

This is how my map works:

  1. Tap on any point on map
相关标签:
2条回答
  • 2021-01-16 00:43

    If you are not using the markers InfoWindow you could set the InfoWindows title or snippet to your id and then retrieve it. I do this with

    myMap.addMarker(new MarkerOptions()
        .title(myTitle)
        .snippet(mySnippet)
        .position(myPosition));
    

    Then to retrieve the id just use:

    myMarker.getTitle()
    

    or

    myMarker.getSnippet()
    

    Here is the example to use the snippet as a tag for the marker:

    public class CustomInfoWindow implements InfoWindowAdapter {
    
        @Override
        public View getInfoContents(Marker marker) {
            View v = LayoutInflater.from(AppCtxProv.getContext()).inflate(R.layout.custom_info_window, null);
            TextView title = (TextView) v.findViewById(R.id.title);
            title.setText(marker.getTitle());
            return v;
        }
    
        @Override
        public View getInfoWindow(Marker marker) {
            return null;
        }
    
    }
    

    Then for the custom layout I used this simple code:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout 
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/white" >
    
            <TextView 
                android:id="@+id/title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
    
    </RelativeLayout>
    

    The AppCtxProv is an Activity class I created that just returns the context:

    public class AppCtxProv extends Application {
    
        @Override
        public void onCreate() {
            super.onCreate();
        }
    
        public static Context getContext() {
            return getApplicationContext();
        }
    
    }
    

    And in the manifest just give the

    android:name="your.package.AppCtxProv"
    

    attribute to the Application tag

    0 讨论(0)
  • 2021-01-16 00:55

    Try with this..

    ( ref. How to remove marker from google map v2? )

    Previously I did told you..Just save marker to your own variables.. and there are a Index number for each and every marker..Hence Index number is provided by you and Google-Marker have itself ID... Google-Marker return ID with 'm1, m2 or m3...'.. so just replace get marker.getId and replace 'm'.. Now you can get marker this Id do match with your Index number.

    // Sample code to get marker id

        String mId = marker.getId();
        mId = mId.replace("m","");
        String clickMarker =  Integer.valueOf(mId);
    

    // hence 'i' is Google-Marker Id... and You have your marker Index value.. match with it. // sample code to get Click marker Id

               for(int k = 0; k<myMarkersHash.size(); k++)
                {
                    if(clickMarker == myMarkersHash.get(k))
                    {
                        // now got k is marker value
                        break;
                    }
                }
    

    // myMarkersHash defined also at ref. link

    0 讨论(0)
提交回复
热议问题