How to add image at specific location in maps? - android

In my project i want to add image at particular location in map.For that i used the following code.
public class Sample extends Activity {
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
#SuppressLint("NewApi")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sample);
// Get a handle to the Map Fragment
GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
LatLng sydney = new LatLng(33.6671688,-117.9053506);
map.setMyLocationEnabled(true);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, 15));
//add overlay
BitmapDescriptor image = BitmapDescriptorFactory.fromResource(R.drawable.categorymap);
GroundOverlayOptions groundOverlay = new GroundOverlayOptions()
.image(image)
.position(sydney, 1000f)
.transparency(0.1f);
map.addGroundOverlay(groundOverlay);
}
}
By using this code the map is displayed like the following screenshot.
But my requirement is add the image at particular location like the following screenshot.For that i have latitude and longitude values also to show the map location.In that location i want to add the image like following screenshot.
So my question is,how to move the image from left to right like the above screenshot.I tried alot for doing this but didnt solve the issue.So please suggest me how to solve this problem.Thanks inadvance to all...

Try to get the exact positions of the corners of the building and uses the method
public GroundOverlayOptions positionFromBounds (LatLngBounds bounds)
Then it should scale with the mapzoom
Another way is to use anchor
EDIT:
GroundOverlayOptions groundOverlay = new GroundOverlayOptions()
.image(image)
.position(sydney, 1000f)
.transparency(0.1f)
.anchor(0.5, 0.5);
This will instead make the lat/lon to be in center of your image.

Related

Android Google map v3 - Limit specific area

Is there any way to prevent user scroll pass a specific area using Google map?
I added a ground overlay on the map, and I don't want user scroll pass it. I found https://developers.google.com/maps/documentation/android-api/views#restrict-panning but user still can see a little map around the overlay (see image below). Any suggestions will be appreciated.
My code:
#Override
public void onMapReady(final GoogleMap mMap) {
final LatLngBounds bounds = new LatLngBounds(new LatLng(10.762657076386494, 106.65704530350968), new LatLng(10.783062032257044, 106.67223733537003));
mMap.addGroundOverlay(new GroundOverlayOptions().image(BitmapDescriptorFactory.fromResource(R.drawable.images))
.positionFromBounds(bounds));
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(bounds.getCenter(), 18));
mMap.setLatLngBoundsForCameraTarget(bounds);
}

GooleMap.setMapType(MAP_TYPE_HYBRID) not working

Method here:
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
LatLng position = new LatLng(x, y);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(position, 15));
geoJsonLayer.addLayerToMap();
}
When I choose: MAP_TYPE_HYBRID, MAP_TYPE_SATELLITE or MAP_TYPE_TERRAIN - map is opened, shape is shown (with JSON), but no background - just small squares, no image.
MAP_TYPE_NORMAL - is working good - getting map image, roads etc. + shape on it.
Where is the problem?
Problem solved by reinstalling application

How to point in direction of movement using MarkerView of Mapbox Android SDK

I am using Mapbox android sdk for my map application, i want to use pointer icon('myIcon' in this case) which always points in the direction where user is moving.
I here is my code :
public void addMarker(MapboxMap mapboxmap) {
// marker view options : setting location and icon
MarkerViewOptions options = new MarkerViewOptions()
.position(latLng)
.anchor(0.5f, 0.5f)
.icon(myIcon);
MarkerView view = options.getMarker();
// added marker on map
mapboxMap.addMarker(options);
}
With marker views we don't expose a way to do this, and your only option is to adjust the marker rotation when the camera is rotated. A better solution would be to use runtime styling and a symbol layer. An example of this can be found in our demo app. To ensure that the marker always points in the correct direction you can use the icon-rotation-alignment property and set it to map. Hope this helps!
Setting rotation on location update {like setRotation(angle_you_want_to_set)} worked of me.
Example :
public void addMarker(MapboxMap mapboxmap, float angle) {
// marker view options : setting location and icon
MarkerViewOptions options = new MarkerViewOptions()
.position(latLng)
.anchor(0.5f, 0.5f)
//set angle of ration for icon
.setRotation(angle)
.icon(myIcon);
MarkerView view = options.getMarker();
// added marker on map
mapboxMap.addMarker(options);
}

Android Google maps V2 How to draw a Custom Views(1/3 filled circle) on map where can i get canvas object to draw

Android Google maps V2 How to draw a Custom Views(1/3 filled circle) on map where can i get canvas object to draw.As all new classes are final classes I can't extend them.
I need to draw a some cutom views on the map.I am upgrading from v1 to v2.The Overlays has been deprecated.I tries with Tile Provider but it is not drawing anything.
exampleButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
GroundOverlayOptions overlayOptions = new GroundOverlayOptions()
.image(BitmapDescriptorFactory.fromResource(R.drawable.testImage))
.position(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()), 8600f, 6500f);
map.addGroundOverlay(overlayOptions);
}
});
This is the code to draw an image at a specified lat long which is working for google maps v2. You can basically get an image of 1/3 filled circle and set it to the lat long you want.
Hope it helps.

Custom map marker change its postition when zoom in or out the map in android

I have made a custom marker,it comes perfectly when map is loaded,but my problem is when i zoom in or out the map,marker changes its position and also when i click on marker info window comes on another postition(not on its top),My code is as below,I cant find solution or idea what i have made wrong,Please save me.
code
private void plotMarkers(ArrayList<MyMarker> markers) {
if (markers.size() > 0) {
for (MyMarker myMarker : markers) {
System.out.println("================rounded bitmaps==========="
+ roundedBitmaps.toString());
// Create user marker with custom icon and other options
MarkerOptions markerOption = new MarkerOptions()
.position(new LatLng(myMarker.getmLatitude(), myMarker
.getmLongitude()));
markerOption.icon(BitmapDescriptorFactory.fromBitmap(myMarker
.getImgURL()));
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(myMarker.getmLatitude(), myMarker
.getmLongitude())).zoom(12).build();
mMap.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));
Marker currentMarker = mMap.addMarker(markerOption);
mMarkersHashMap.put(currentMarker, myMarker);
mMap.setInfoWindowAdapter(new MarkerInfoWindowAdapter());
}
}
}
Custom Markers work in a different way as the standard markers. The problem you are facing is a known issue, The best way to deal with this are as follows:
Make sure that the image for the custom marker is symmetrical and id perfectly aligned to the anchor.
The info window should also be similarly aligned symmetrically in the center of the marker, else it will look ugly. Please note that the Custom marker icons often require a different anchor. For the info window, use a custom info window layout (with a custom background) to align it correctly to the marker.

Categories

Resources