All the basic stuff, I have a SupportMapFragment, everything works fine, I just need to know if there is a short way of making the map follow my position or do I have to move the camera every time the location changes?
Well first of all thanks for your time Naskov but this is not a mapView, it's a MapFragment. the code I am using right now (in case someone needs it) is this (onUpdateLocation)
if (mapFragment.theMap != null) {
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(getLocation().getLatitude(),
getLocation().getLongitude())).zoom(14.0f).build();
CameraUpdate cameraUpdate = CameraUpdateFactory
.newCameraPosition(cameraPosition);
mapFragment.theMap.moveCamera(cameraUpdate);
}
I was just wondering if there is some built in method for doing it, also because this doesnt go very smooth. If someone comes up with a better idea please post it
It's not exactly what you want, but you can use:
map.setMyLocationEnabled(true);
To add a button to your map at top right corner (Like in the native Google Maps application) that will allow the user change the camera position to his location when he wants.
Related
I have been working on retrieving GPS locations using Google's FusedLocationProvider API for about a week now. I have successfully gotten close to retrieving accurate gps data.
Currently the marker jumps around the map, instead I want it to smoothly animate like Google Maps, Waze, etc. I have searched the entire internet looking for a solution and have not found anything.
You could use animateCamera() method to set focus to new latlng.
CameraPosition cameraPosition = new CameraPosition.Builder().target(
new LatLng(17.385044, 78.486671)).zoom(12).build();
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
This will result in smooth transition.
PS:Play with the zoom to make it more realistic.
You are looking for this
I have created an application in which I am trying to show user's movement by animating marker position.
Using Google map V2.
Location updates using location client.
Animating marker using new location.
But comparing with Google map navigation, there is no continuity in rendering navigation.
Can anyone suggest a better approach? Thanks!
For continuity, I think you need to fetch regular location updates from location client by giving location request like this.
LocationRequest request = LocationRequest.create()
.setInterval(0).setFastestInterval(0)
.setSmallestDisplacement(0)
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
Then for smooth animation you can follow the approach Steve Benett mentioned. here
The last case you mentioned in the comment about the path. I also had the same issue in one of my app. I tried with gps route simulator app to mock a route. then comparing my app and google map, googlemap followed the correct road path while my app's marker was moving slightly shifted from road. Then I tried some tweaks with marker. Like this
mPositionMarker = mMap.addMarker(new MarkerOptions()
.flat(true)
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.positionIndicator))
.anchor(0.5f, 0.5f)
.position(
new LatLng(location.getLatitude(), location
.getLongitude())));
This worked for me. This positioned my marker on same location as of google map. (Depends on the accuracy of location though).
Thanks for the answer here
I have a specific problem with Google Maps for Android. I should be able to make Google Maps look like the map on this page www.bam.brno.cz, but I'm new to Goole Maps for Android so I don't know if there's a way to do it.
I don't have any of those map images, but i guess there should be a way to get it from the internet (like WMS or something). If I was eventually able to save them and use them offline that would be great, but if not and the app would have to use data connection, it's also ok.
I already got app with google maps, so the question is just about how to get the map images and replace default google maps images.
Also if that wouldn't be posible, I would like to know what other options I have(like if theres some other map images I can use and how)
PS: not sure how it's called correctly: map images/map tiles
EDIT: I don't care about the objects, I know how to do them. I don't know how to get the whole map, the tiles it's made from. I'm already familiar with markers and camera moving etc.
Yes you can use marker for same.
You can try some thing like ..
m = myMap.addMarker(new MarkerOptions()
.position(new LatLng(startLatLng.latitude, startLatLng.longitude))
.title("Vivek Test"));
Here m is Marker;
and myMap is GoogleMap
Complete structure like this ..
myMap = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
//myMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
myMap.setMyLocationEnabled(true);
myMap.moveCamera(CameraUpdateFactory.newLatLng(startLatLng));
myMap.animateCamera(CameraUpdateFactory.zoomTo(20), 2000, null);
m = myMap.addMarker(new MarkerOptions()
.position(new LatLng(startLatLng.latitude, startLatLng.longitude))
.title("Vivek Test"));
Hope it helps. Cheers!
There is at least one file holding a series of coordinates (Latitude, Longitude) of each of the colored lines. Get those coordinates and use Polylines. These should take care of the colored lines. The grey dots would be Markers and these could be in the same file. Assuming that GoogleMaps has similar places names, then with these two you ought to be able to reproduce the map.
We all know that some of the predefined landmarks on Google Maps does not appear on a lower zoom level, but on a higher zoom level, it suddenly appears. I would like to know If I can make a customized marker not appear at lower zoom levels, then appear at higher ones.
EDIT: Here is a snippet of my code.
// Changing marker icon
marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.gasbig));
// adding marker
map.addMarker(marker);
//position on Center
CameraPosition cameraPosition = new CameraPosition.Builder().target(
new LatLng(14.635356, 121.03272914)).zoom(16).build();
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
map.setOnCameraChangeListener(new OnCameraChangeListener() {
#Override
public void onCameraChange(CameraPosition arg0) {
if(arg0.zoom > 7){
marker.visible(true);
}
}
});
I tried the suggestion of MaciejGórski but the marker still appears on all zoom levels. I'm sorry about the question I'm still an android newbie.
Thanks in advance.
You can do that for any Marker you want: call setVisible in OnCameraChangeListener.onCameraChange callback with true or false depending on CameraPosition.zoom value.
Edit after question edit:
You need to keep a reference to Marker instead of MarkerOptions:
// adding marker
marker = map.addMarker(markerOptions);
and call setVisible on that marker:
#Override
public void onCameraChange(CameraPosition cameraPosition) {
marker.setVisible(cameraPosition.zoom > 7);
}
Note: setVisible is always called there, but this might not be optimal when using many Markers.
You could possibly do it by modifying my answer to: Android Maps v2 - animate camera to include most markers
Otherwise using Android Maps Extensions might be a good choice. No experince with your specific needs though.
Just realized I might have misunderstood the question. Thought you meant your own markers. Nevertheless have a look at the extensions library. Could very well be that they have something useful.
I am getting a blue screen when I load my Google Maps on Android. I don't know what I am doing wrong, this is my code for getting the locations:
MapView mapView = (MapView) findViewById(R.id.mapDire);
Route route = directions(new GeoPoint((int)(2*1E6),(int)(34*1E6)),
new GeoPoint((int)(3*1E6),(int)(36*1E6)));
I think can be two things
Your coordinates are 0,0 and the map is opening in the ocean
Something wrong with your API Key
In the first case try zoom out a lot of times and try to see some continent.
In the second try to read the documentation or/and try this link
I hope this helps.
I have this problem in my application and see below code in onlocationchanged method and resolve it.
LatLng myCoordinates = new LatLng(location.getLatitude(), location.getLongitude());
mMap.moveCamera(CameraUpdateFactory.newLatLng(myCoordinates));
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 17.0f));
marker.setPosition(myCoordinates);
Normally blue screen means your Google API key didn't work.
GoogleMaps - Actual Map not showing
If your map is not showing, only grids/blank screen showing, that's because your Map API key is missing or incorrect. Sign up for Google Android Map API.
Try this the link for more info.
There could 3 reasons as to why You see blue screens
Your Long/Lat Points to Water region - or Ocean region, Invariably there's nothing wrong just you Long/Lat Pointing to Water which is blue in color.
Your Long/Lat is wrong and nothing comes up
Your API key is wrong which can be corrected on your Android manifest file
directory: Android/app/src/main/AndroidManifest.xml