Updated 29 May 2017
In the last part of the working with AMaps we learned about how to show a basic map in your activity. In this section we will learn about using different may type (Like NORMAL, SATELLITE, NIGHT etc.) in the app and adding markers.
We will be considering that you have already applied the basic map on the app if not then you can go to this link and learn how to do it.
After this, you have to create some buttons in your layout which will control the map types and on the button click all you need to do is call the setMapType of AMap‘s object.
1 2 3 4 5 6 7 8 |
// For normal map type your_amap.setMapType(AMap.MAP_TYPE_NORMAL); // For satellite map type your_amap.setMapType(AMap.MAP_TYPE_SATELLITE); // For night map type your_amap.setMapType(AMap.MAP_TYPE_NIGHT); // For navigation map type your_amap.setMapType(AMap.MAP_TYPE_NAVI); |
This will change the map type and your map will work accordingly.
Now let us see how to add the marker on your map. It is quite easy actually, there is a MarkerOptions class which will help you to do that. Try the below code with a Latlng and it will add a marker on your map.
1 2 3 4 5 6 7 |
private void addMarkersToMap() { MarkerOptions your_marker_option = new MarkerOptions().icon(BitmapDescriptorFactory .defaultMarker(BitmapDescriptorFactory.HUE_AZURE)) .position(latlng) .draggable(true); your_amap.addMarker(markerOption); } |
In the above code BitmapDescriptorFactory.HUE_AZURE defines the type of your marker. They have provide inbuilt markers with various color. You can go for HUE_BLUE, HUE_RED etc.
After the MarkerOptions object is initialized you need yo call the addMarker function of your AMap‘s object and it will draw a marker on the map.
Thank you very much, this is Vedesh Kumar signing off.
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.