Zoom Maps do , width and length of the route Android Studio - java

I am looking for a solution to my problem. My application uses Google Maps and Google Play Service. My application gets the user's position and writes to the array. On the basis of the points I make a route. When I display it on the map, the map is far away. I'd like to bring. The problem is that the route can have a length from 50m to 1000km. Someone please help me ? Thank you very much!
My maps can look as below (BLUE LINE)!

I see you already save the user's position, so it's pretty simple. Just pick the first and last positions and use a CameraUpdate to display the route to the user:
LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(first_position_latlng);
builder.include(last_position_latlng);
LatLngBounds bounds = builder.build();
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding_if_any);
mMap.animateCamera(cu);
Just keep in mind that this works for simple routes like the one you linked. For more complex ones instead of the first and last position, you'll need to find the the furthest southwest and northeast points

Related

Getting individual coordinates from OSMDroid routing, to use in finding elevations on trip

I am trying to create a hill finder application
Like this
The user enters a starting location, and an end location. With the end goal of displaying a chart with the elevations of the road in the trip
Currently, I have managed to get it to create a route between point A and point B. I needed to use routing, since in my use case, the user has to stay on the road and can't just draw a straight line
code so far:
RoadManager roadManager = new OSRMRoadManager(requireContext(), "MY_USER_AGENT");
ArrayList<GeoPoint> waypoints = new ArrayList<>();
waypoints.add(startPoint);
GeoPoint endPoint = new GeoPoint(48.069842, -1.712637);
waypoints.add(endPoint);
Road road = roadManager.getRoad(waypoints);
Polyline roadOverlay = RoadManager.buildRoadOverlay(road);
map.getOverlays().add(roadOverlay);
map.invalidate();
Drawable nodeIcon = getResources().getDrawable(R.drawable.ic_baseline_location_on_24);
for (int i=0; i<road.mNodes.size(); i++){
RoadNode node = road.mNodes.get(i);
Marker nodeMarker = new Marker(map);
nodeMarker.setPosition(node.mLocation);
nodeMarker.setIcon(nodeIcon);
nodeMarker.setTitle("Step "+i);
map.getOverlays().add(nodeMarker);
}
Took this from the guide on the osmdroid bonus pack github page
I already have a system in place to load elevations from coordinates elsewhere in the app. I just need to get the coordinates from the route. At least every 10 feet or so, not just the intersections
I'm hoping this is possible with osmdroid, especially since this has been done with google's apis. However, that code was not open, and I don't want to be charged per usage
My best guess was something with projection(), but I barely know how to use it
NOTE: I won't be using this for long distances, probably at most a mile is what the user would need
I don't think omsdroid can do this out of the box. However you can solve this:
roadOverlay.getPoints() will give you ArrayList containing the "turning" points. You can then apply some math to calculate what you need. I would do it like this:
Calculate distance in feet between two turning points. Calculate distance between 2 GPS coordinates
Divide the distance by 10 feet (as mentioned in your post) and subtract 1. You will get the number of points between the 2 turning points.
Apply some more math to get lat and lng of each of the points on the road. You can inspire here. How to calculate the points between two given points and given distance? or Calculate point between two coordinates based on a percentage
You can now use the elevation API for the points. Do not forget to get the elevation of the turning points, too.
Get the next 2 turning points and repeat. :-)

How to display user position on custom made map in indoor navigation?

I am creating a small indoor navigation android application using wifi fingerprinting. Since it is a small scale application I am using a custom made map(which is basically a png image)I want to show the location of the user on a particular spot on the image and update it accordingly as the user moves. So what is the best way to do it?I thought of dividing image like x-y axis and placing the dot on the axis according to value(Tell me this also).
It involves a lot of Bitmap manipulation . Take that marker as an ImageView which you should be able to put it across your FrameLayout inside which you would have the root Map imageView/ map view and then over the top of it . you should be able to put that marker on top of it. but if its a static marker image. then you should be able to use LayoutParams and put on top of the root map view.
There are hundreds of ways.
One easy way would be to use:
https://github.com/chrisbanes/PhotoView
That lib handles scaling, panning, etc and even provides access to the matrix used.
It is important to note too that the users coordinates need to be translated into scale.
In one of my apps, I dont handle user locations, but I allow a user to put pins on the map. My Pin object contains XY coords relative to the original map size.
To convert to the device/image scale size, I do this:
float[] convertedPin = {pin.getX(), pin.getY()};
getImageMatrix().mapPoints(convertedPin);
getImageMatrix() is provided with the library posted above.
Then, I modified the libs onDraw():
for (Pin pin : pins) {
if (pin.isVisible()) {
float[] goal = {pin.getX(), pin.getY()};
getImageMatrix().mapPoints(goal);
if (pin.getPinBitmap() != null) {
float pinSize = TypedValue.applyDimension(COMPLEX_UNIT_DIP, pin.getPinSize(), getContext().getResources().getDisplayMetrics());
canvas.drawBitmap(pin.getPinBitmap(), goal[0] - (pinSize / 2f), goal[1] - pinSize, null);
}
canvas.save();
}
}

Android - Get orientation (Compass like) where phone is pointing at

I have an array of Marker (google maps markers) with longitude and latitude.
I want to create some sort of radar like view that'll display these markers as points where I'm looking toward their directions with an angle of 45°.
Do you guys have any idea how I can say "This marker is behind me, this marker is in front of me".
I guess I should apply cos and sin considering my orientation, but that's too blurry atm.
Hope you'll help :)
Thanks
I assume you already know your location and orientation. You can then calculate the directions of the array of markers using computeHeading() method of Google maps Geometry Library on your current location and the points. Then you can adjust those values based on your current orientation.

creating a circular route from distance in android app

I would like to create a circular route from distance.
First, I get current position, and then create a circular route based on the specified distance.
But I don't know how to achieve this at all.
I couldn't find any helpful methods in Google Maps API.
Is there any way to achieve this?
You can do that easily as Android Google Maps provides that API.
GoogleMap map;
// ... get a map.
// Add a circle in Sydney
Circle circle = map.addCircle(new CircleOptions()
.center(new LatLng(-33.87365, 151.20689))
.radius(10000)
.strokeColor(Color.RED)
.fillColor(Color.BLUE));
Take a look at this official Doc.
The only change you need to make is to pass the current location's Lat/Lng to the center method.
You can follow this tutorial to get the current location coordinates of a person.

Adding 9000 markers on Google Maps API for Android. App crashes. How to solve?

I have about 9000 areas (i.e. 9000 lines) I have sourced in a CSV file.
There are 6 location related values in each line.
1) I, therefore, have 6 arraylists holding about 9000 values each (doing this in background Async Task) . The size of each of these array lists says "6227" or something like that - so I need to troubleshoot if some values are not being added or is there an arraylist size limitation?
2) Now, I am trying to create 9000 markers with the associated values in the title and snippet section. Please point me to a good tutorial on creating a custom marker with text views. I went to some and couldn't understand anything.
3) My third question is simple: How to efficiently handle this? I am a newcomer and I hate to say that most of the tutorials I have seen on clustering or hiding are impossible to understand. Please provide an understandable description of how to handle this problem. I am begging you.
This is how I collect the data from my CSV file; This is in the background task of AsynTask; And on PostExecute, I pass these values to the method that actually plots the marker on the Google Map.
String mLine = reader.readLine();
while (mLine != null) {
String[] coord = mLine.split(",");
Names.add(coord[0]);
city.add(coord[1]);
country.add(coord[2]);
Code.add(coord[3]);
arrLat=Double.parseDouble(coord[4]);
arrLong=Double.parseDouble(coord[5]);
arrLong=Double.parseDouble(coord[1]);
arrRadius=Double.parseDouble(coord[2]);*/
LatLng thisLoc = new LatLng(arrLat,arrLong);
coordinates.add(thisLoc);
mLine = reader.readLine();
}
For the arraylist size limitation, it should hold up to Integer.MAX_VALUE, you may refer to this link.
I would recommend Clusterer for this particular problem. You may refer to this github sample of MarkerClusterer in which every method has a description, and should be easier to understand. Then, using Viewport Marker Manager to optimize your app's performance. This turns off the markers that are not within the bounds of the screen especially when the user is zooming.
Lastly, in customizing marker with Textview, this link might be helpful. What it does is generate a bitmap and attach it to a marker.
This is the sample code for the custom marker as taken from the link:
Bitmap.Config conf = Bitmap.Config.ARGB_8888;
Bitmap bmp = Bitmap.createBitmap(200, 50, conf);
Canvas canvas = new Canvas(bmp);
canvas.drawText("TEXT", 0, 50, paint); // paint defines the text color, stroke width, size
mMap.addMarker(new MarkerOptions()
.position(clickedPosition)
//.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker2))
.icon(BitmapDescriptorFactory.fromBitmap(bmp))
.anchor(0.5f, 1)
);
Good luck!

Categories