In order to add annotations to the Map, the user needs to create an Annotation object first. The Annotation class contains the interface that clients use to configure the display properties of the annotation. The information required to render an annotation is:
Location: The position of the annotation in the map, using Android's Location class.
Graphic: The graphic info, if any, used to present the image for the annotation. This can be set via resource ID, Drawable, and a variety of other methods. (This information is optional, but the annotation requires either Graphic or TextDisplayInfo.)
TextDisplayInfo: The text display info, if any, used to present textual information for the annotation. (This information is Optional, but requires either Graphic or TextDisplayInfo.)
All annotations are instantiated via a Factory before client adds additional configuration and passes them to the MapView for rendering.
How to create an annotation:
Here is sample code for how to create annotations to MapView.
1234567
//Create Annotation with resource IDLocationlocation=newLocation("");location.setLatitude(37.402295);location.setLongitude(-122.059237);Annotationannotation=AnnotationFactory.create(context,R.drawable.map_pin_green_icon_unfocused,location);//Any additional settings here...
1234567
//Create Annotation from resource IDvallocation=newLocation("")location.latitude=37.402295location.longitude=-122.059237valannotation=AnnotationFactory.create(context,R.drawable.map_pin_green_icon_unfocused,location)//Any additional settings here...
How to add annotations:
Here is sample code for how to add annotations to MapView.
123456789
Annotationannotation=...;// Previously created annotation//Any additional settings here...//Create list of annotationsList<Annotation>annotations=newArrayList<>(Arrays.asList(annotation));//Note: Must be done from main thread!mapView.annotationsController().add(annotations);
123456789
valannotation=...;// Previously created annotation//Any additional settings here...//Create list of annotationsvalannotations=arrayListOf(annotation)//Note: Must be done from main thread!mapView.annotationsController().add(annotations);
How to remove annotations:
Here is sample code for how to remove annotations from MapView.
1234567
Annotationannotation=...;// Previously created annotation//Create list of annotationsList<Annotation>annotations=newArrayList<>(Arrays.asList(annotation));//Note: Must be done from main thread!mapView.annotationsController().remove(annotations)
1234567
valannotation=...// Previously created annotation//Create list of annotationsvalannotations=arrayListOf(annotation)//Note: Must be done from main thread!mapView.annotationsController().remove(annotations)
Show POI on map
There are some easy APIs for users to show point of interest (POI) on map.
These APIs will help users to:
* Mapping POIs to Annotations.
* Manage the cache of POIs.
* Add an annotation when the location of the POI is within the screen.
* Remove an annotation when the location of the POI is out of the screen.
The information required to show POIs is:
SearchController: The controller of POIs and related annotations.
SearchEngine: The search engine used to search POIs on the screen.
PoiAnnotationFactory: The factory of Annotation. Users can create their own annotation styles with POI by implementing a custome factory.
How to display POI on map:
Here is sample code for how to initialize searchController.