Reputation: 5
it is fail to mark LOCATION2 on map , but is successful if replace it using LOCATION1.
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
LatLng LOCATION1 = new LatLng(18.79038, 98.98468);
int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_CALENDAR);
mMap.setMyLocationEnabled(true);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LOCATION1, 13));
vehicles=query.QueryVhe();
Double lat=vehicles.get(0).getLatitude(); //get latitude.
Double lng=vehicles.get(0).getLongitude();//get Longitude.
//I am sure that lat and lng have already got data here.
//here is a problem that it is fail to mark LOCATION2.
LatLng LOCATION2 = new LatLng(lat, lng);
mMap.addMarker(new MarkerOptions()
.title("Sydney")
.snippet("Chaing Mai.")
.position(LOCATION2));// But if it is successful if LOCATION2 were LOCATION1.
}
}
Upvotes: 0
Views: 76
Reputation: 986
You can add your marker in following manner.
Marker marker = map.addMarker(new MarkerOptions()
.position(new LatLng(37.7750, 122.4183)) // those are dummy values for lat and long
.icon(BitmapDescriptorFactory.fromResource(R.drawable.location))
.title("My Location on Map")
.snippet("details"));
Upvotes: 2
Reputation: 171
use this code if it helps you please make it as right
mMap.addMarker(new MarkerOptions()
.title("My Location")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.myloc))
.anchor(0.0f, 1.0f) // Anchors the marker on the bottom left
.position(new LatLng(lat, lon)))
.setDraggable(true);
if you dont need anchor or setdraggable you can remove it
Upvotes: 1