Set marker on Polyline in google maps - java

I've tried to make possible choice on polyline in google maps. But I'm stuck.
For example: I have 10 points (with lines).
by using this part of code:
polylines = new PolylineOptions();
polylines.color(getResources().getColor(R.color.poly_line_color));
//add path points, set colour, etc. here
polyline = mMap.addPolyline(polylines);
polyline.setPoints(latLngs);
polyline.setClickable(true);
mMap.setOnPolylineClickListener(new GoogleMap.OnPolylineClickListener() {
#Override
public void onPolylineClick(Polyline polyline) {
Logger.e("id : "+polyline.getPoints());
}
});
we can easy detect click on polyline. But - I can't detect current coordinates (latitude/longitude) for this click.
I tried method
"PolyUtil"
from another library - but this is work randomly and not correct. And really - look like it does not work. 10 clicks on map = 1 good point which is not on polyline or near this line.
Polyline polyline has only few methods and only one normal "getPoints()" but its returned all points.
Can anyone help me with this? I checked a lot of posts on SO but none helped me.

map.setOnPolylineClickListener(new GoogleMap.OnPolylineClickListener() {
polyline.getPoints()
});
Try this function polyline.getPoints() in your code. This may help you. Thanks

Related

How to get all latlng of Route between two points in OSM

I'm working on app using open street map. I have draw route between two points. I want to get list of all latitudes and longitudes on the route polyline. If anyone knows please answer me.
**Here is the answer
just play with your polyline **
Polyline roadOverlay = RoadManager.buildRoadOverlay(road1);
roadOverlay.getPoints();

Center Google route on screen

I would like to center a route that is returned from google directions api on the screen? I have tried to use CameraUpdateFactory.newLatLngBounds but it seems to limit the user from moving to a certain part of the map.
All i would like to do is show the route centered on the screen rather than my current location?
Ok,
I managed to find a solution if anyone needs help with something similar. Although I am still trying to fix the calculating the zoom issue, where it doesn't zoom in to have the route fit in the screen as apposed to hard coding a zoom value
LatLng northEast = new LatLng(aBoundary.getNortheast().getLat(), aBoundary.getNortheast().getLng());
LatLng southWest = new LatLng(aBoundary.getSouthwest().getLat(), aBoundary.getSouthwest().getLng());
LatLngBounds latLngBounds = new LatLngBounds(southWest, northEast);
mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLngBounds.getCenter(), mGoogleMap.getCameraPosition().zoom));
the aBoundary object is the Bounds object that sits inside the Route object from the response.

Pointing to a location in Google Maps in Android Studio

I am working on an app using android studio where cell data is saved in a database with it's corresponding location in latitude and longitude coordinates and users can access this data when there is no service to find a way to a good to better service. The data will be drawn to a google maps activity and color coordinated to represent the color but I also want to add an arrow the points from current location to the best cell service within a radius that I will set up.
Is it possible to draw an arrow to accomplish the task of pointing to a data point that is drawn? any info that points me in the right direction or the answer will help, thank you.
EDIT
The arrow design I have in mind points to the better signal but does not connect to the other location. I will figure out a more complex pointing device later in development so I am just looking for information on the possibility of a short pointer arrow that represents a "GO THAT WAY" response.
You can use Ground overlays , where you can set particular image at given latlong.
LatLng NEWARK = new LatLng(40.714086, -74.228697);
GroundOverlayOptions newarkMap = new GroundOverlayOptions()
.image(BitmapDescriptorFactory.fromResource(R.drawable.newark_nj_1922))
.position(NEWARK, 8600f, 6500f);
map.addGroundOverlay(newarkMap);
for rotating the image you can look
https://stackoverflow.com/a/4332278/7386743
Are you talking about creating line between the two points ? Could you clearify more what do you exactly need ?
If it creating a line then you can use polyline
GoogleMap map;
Polyline line = map.addPolyline(new PolylineOptions()
.add(new LatLng(51.5, -0.1), new LatLng(40.7, -74.0))
.width(5)
.color(Color.RED));

Android - How can I achieve this Google Maps animation?

This is how I'm currently using my google map;
mapFragment = ((SupportMapFragment) getChildFragmentManager()
.findFragmentById(R.id.map)).getMap();
mapFragment.setMyLocationEnabled(true);
mapFragment.setMapType(GoogleMap.MAP_TYPE_HYBRID);
mapFragment.getUiSettings().setMapToolbarEnabled(false);
mapFragment.getUiSettings().setScrollGesturesEnabled(false);
mapFragment.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
It produces a full screen map which for some reason is completely zoomed into the ocean so the map is just one big, blue pixel until you keep zooming out.
What I want to do:
When this activity gets opened, the map should have the user's location in the center, and the map should be as zoomed out as possible (as if you are lookin at a 2D globe)
The map should then zoom/animate into the player's location to give the same effect as when you press the location button on the top right of the map.
I have looked online, tried a few things and haven't had any luck with this. If anybody can walk me through this or give me a link to a nice guide it would be highly appreciated!
To achieve what you want, you should:
1) get the user's position, you can use the last known position so that your main activity would not hang and wait for the GPS return a location.
LocationManager locationManager = (LocationManager)getSystemService
(Context.LOCATION_SERVICE);
Location getLastLocation = locationManager.getLastKnownLocation
(LocationManager.PASSIVE_PROVIDER);
2) set the zoom level to 1, which is the smallest zoom level, the 2D globe; also you can center the map using the user location too.
googleMap.moveCamera(CameraUpdateFactory.zoomTo(1));
3) animate the camera to zoom into the user location with a zoom level 20 (the largest zoom level). One thing to notice is that, you might want to wait until the 2D globe maps is loaded so that user can see the zoom happens.
googleMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
public void onMapLoaded() {
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder()
.target(new LatLng(userLocation.getLatitude(), userLocation.getLongitude()))
.zoom(20)
.build()));
}
});
I tried that and it works fine for me. Let me know if it is unclear, and hope it helps.

Object relative to the image while zooming in or out

I have a map that is being drawn on the screen inside a VisualizationView. I am able to zoom in and out on this map, depending on where I focused inside this view using the touch functionality.
I also toggle between zooming in and drawing on this map. When I draw an arrow on the map and switch back to zooming in. I want the arrow I drawed on the map to stay at the same spot relative to the map I am zooming in and out on. Meaning the x and y pos of this arrow have to be adjusted.
I have all the variables needed I just dont know how to solve this since its math related.
Can someone explain to me how I can solve this math wise. I tried looking on the internet but I could not find a good explanation. Also the map resolution on the Tablet is always 576 x 576.
public void onZoom(final double focusX, final double focusY,
final double factor) {
//pseudocode
Triangle.x = ..
Triangle.y = ..
Triangle.repaint();
//peusocode
}
The code for the zooming is as following straight from the Library.
public void zoom(double focusX, double focusY, double factor) {
synchronized (mutex) {
Transform focus = Transform.translation(toMetricCoordinates((int) focusX, (int) focusY));
double zoom = RosMath.clamp(getZoom() * factor, MINIMUM_ZOOM, MAXIMUM_ZOOM) / getZoom();
transform = transform.multiply(focus).scale(zoom).multiply(focus.invert());
}
}
I hope someone can explain the math behind solving this.
I'm not directly familiar with the library you're using, but to move the location of the arrow (triangle) to its new location you should apply the same transform to it as you do to the map.
Think of it this way: Before zooming, the location of the arrow (the center or head of the arrow, however you define "location") and the point on the map it's pointing to have the same coordinates. After zooming, the point on the map will have moved to a new location and you want the arrow to move to that same new location, thus you need to use the same transform. Like I said, I'm not familiar with the library you're using so I can't tell you exactly how to do that, but that's where you want to be.
Note, however, that you only want to transform one point of the arrow/triangle and draw the other points relative to it. If you transform all 3 you'll end up with the arrow getting larger and smaller as you zoom in and out (which I assume you don't want).

Categories

Resources