I'm developing an Android App for Tablets, which shows two maps with markers in master-detail-layout.
Both maps contain different markers. When I start to move the camera in one of the maps, markers on the other map start to jump/flicker and sometimes even stay in wrong locations.
I was able to reproduce the problem with the google-maps android-samples
by simply adding some markers to two of the maps, nothing more. The flickering is actually far worse than visible in the gif.
gif displaying jumping markers
Here's the whole changed Activity for completeness:
public class MultiMapDemoActivity extends AppCompatActivity {
private static final LatLng BRISBANE = new LatLng(-27.47093, 153.0235);
private static final LatLng MELBOURNE = new LatLng(-37.81319, 144.96298);
private static final LatLng SYDNEY = new LatLng(-33.87365, 151.20689);
private static final LatLng ADELAIDE = new LatLng(-34.92873, 138.59995);
private static final LatLng PERTH = new LatLng(-31.952854, 115.857342);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.multimap_demo);
final SupportMapFragment firstMapFragment =
(SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map1);
firstMapFragment.getMapAsync(new OnMapReadyCallback() {
#Override
public void onMapReady(GoogleMap googleMap) {
addMarkers(googleMap, multiplyMarkerPosition(BRISBANE));
addMarkers(googleMap, multiplyMarkerPosition(MELBOURNE));
addMarkers(googleMap, multiplyMarkerPosition(SYDNEY));
addMarkers(googleMap, multiplyMarkerPosition(ADELAIDE));
addMarkers(googleMap, multiplyMarkerPosition(PERTH));
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(ADELAIDE, 4f));
}
});
final SupportMapFragment secondMapFragment =
(SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map2);
secondMapFragment.getMapAsync(new OnMapReadyCallback() {
#Override
public void onMapReady(GoogleMap googleMap) {
addMarkersBlue(googleMap, multiplyMarkerPosition(new LatLng(51.51, 0)));
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(51.51, 0), 4f));
}
});
}
public List<LatLng> multiplyMarkerPosition(LatLng position) {
final LinkedList<LatLng> positions = new LinkedList<>();
final double latitude = position.latitude;
final double longitude = position.longitude;
final double delta = 1;
positions.add(new LatLng(latitude, longitude + delta));
positions.add(new LatLng(latitude, longitude - delta));
positions.add(new LatLng(latitude, longitude));
positions.add(new LatLng(latitude - delta, longitude + delta));
positions.add(new LatLng(latitude - delta, longitude - delta));
positions.add(new LatLng(latitude - delta, longitude));
positions.add(new LatLng(latitude + delta, longitude + delta));
positions.add(new LatLng(latitude + delta, longitude - delta));
positions.add(new LatLng(latitude + delta, longitude));
return positions;
}
public void addMarkers(GoogleMap map, List<LatLng> positions) {
for (LatLng latLng : positions) {
map.addMarker(new MarkerOptions().position(latLng));
}
}
public void addMarkersBlue(GoogleMap map, List<LatLng> positions) {
for (LatLng latLng : positions) {
map.addMarker(
new MarkerOptions()
.position(latLng)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
}
}
}
I couldn't find out whether this is a known bug or an unsupported mode of operation. If you have any ideas or possible workarounds, please let me know. Thanks.
Related
I'm currently developing an android application that would allow users to draw Polylines with Markers or point in the polyline when user long press on points how to dragline with points move also line would be move on the map. how do I achieve this I drag marker but cant move marker
public class MainMapActivity extends AppCompatActivity {
GeoPoint startPoint;
MapView map;
Road road;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_map);
map = (MapView) findViewById(R.id.map);
map.setTileSource(TileSourceFactory.MAPNIK);
map.setBuiltInZoomControls(true);
map.setMultiTouchControls(true);
GpsTracking gps=new GpsTracking(MainMapActivity.this);
if (gps.canGetLocation()) {
double latitude = gps.getLatitude();
double longitude = gps.getLongitude();
startPoint = new GeoPoint(latitude, longitude);
Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();
} else {
gps.showSettingsAlert();
}
// GeoPoint startPoint = new GeoPoint(48.13, -1.63);
IMapController mapController = map.getController();
mapController.setZoom(17);
mapController.setCenter(startPoint);
Marker startMarker = new Marker(map);
startMarker.setPosition(startPoint);
startMarker.setDraggable(true);
startMarker.setOnMarkerDragListener(new OnMarkerDragListenerDrawer());
startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
map.getOverlays().add(startMarker);
//Set-up your start and end points:
RoadManager roadManager = new OSRMRoadManager(this);
ArrayList<GeoPoint> waypoints = new ArrayList<GeoPoint>();
waypoints.add(startPoint);
GeoPoint endPoint = new GeoPoint(31.382108, 74.260107);
waypoints.add(endPoint);
// retreive the road between those points:
Road road = roadManager.getRoad(waypoints);
// build a Polyline with the route shape:
Polyline polyline=new Polyline();
polyline.setOnClickListener(new Polyline.OnClickListener() {
#Override
public boolean onClick(Polyline polyline, MapView mapView, GeoPoint eventPos) {
return false;
}
});
Polyline roadOverlay = RoadManager.buildRoadOverlay(road);
//Polyline to the overlays of your map:
map.getOverlays().add(roadOverlay);
//Refresh the map!
map.invalidate();
//3. Showing the Route steps on the map
FolderOverlay roadMarkers = new FolderOverlay();
map.getOverlays().add(roadMarkers);
Drawable nodeIcon = ResourcesCompat.getDrawable(getResources(), R.drawable.marker_node, null);
for (int i = 0; i < road.mNodes.size(); i++) {
RoadNode node = road.mNodes.get(i);
Marker nodeMarker = new Marker(map);
nodeMarker.setDraggable(true);
nodeMarker.setOnMarkerDragListener(new OnMarkerDragListenerDrawer());
nodeMarker.setPosition(node.mLocation);
nodeMarker.setIcon(nodeIcon);
//4. Filling the bubbles
nodeMarker.setTitle("Step " + i);
nodeMarker.setSnippet(node.mInstructions);
nodeMarker.setSubDescription(Road.getLengthDurationText(this, node.mLength, node.mDuration));
Drawable iconContinue = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_continue, null);
nodeMarker.setImage(iconContinue);
//4. end
roadMarkers.add(nodeMarker);
}
}
class OnMarkerDragListenerDrawer implements Marker.OnMarkerDragListener {
ArrayList<GeoPoint> mTrace;
Polyline mPolyline;
OnMarkerDragListenerDrawer() {
mTrace = new ArrayList<GeoPoint>(100);
mPolyline = new Polyline();
mPolyline.setColor(0xAA0000FF);
mPolyline.setWidth(2.0f);
mPolyline.setGeodesic(true);
map.getOverlays().add(mPolyline);
}
#Override public void onMarkerDrag(Marker marker) {
//mTrace.add(marker.getPosition());
}
#Override public void onMarkerDragEnd(Marker marker) {
mTrace.add(marker.getPosition());
mPolyline.setPoints(mTrace);
map.invalidate();
}
#Override public void onMarkerDragStart(Marker marker) {
//mTrace.add(marker.getPosition());
}
}
}
Does anyone know how I can achieve this? above is a snippet of my codes. Thanks!
I'm new to programming in Android, I'm developing an application which shows some markers that I'm giving you by code, when adding a cluster, it marks me a few default points.
I would like to know how do I change those default points in the cluster and add the markers to the points I want?
private void addItems() {
double lat = 3.424014;
double lng = -76.536218;
for (int i = 0; i < 5; i++) {
double offset = i / 60d;
lat = lat + offset;
lng = lng + offset;
MyItem offsetItem = new MyItem(lat, lng);
mClusterManager.addItem(offsetItem);
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
btnclute=(Button)findViewById(R.id.btn_cluster);
//cluster
btnclute.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(3.422504, -76.538128), 13));
mClusterManager = new ClusterManager<MyItem>(getBaseContext(), mMap);
mMap.setOnCameraIdleListener(mClusterManager);
mMap.setOnMarkerClickListener(mClusterManager);
addItems();
}
});
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
#Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mapa= googleMap;
// Add a marker in Sydney and move the camera
//LatLng sydney = new LatLng(-34, 151);
//Marker
//Estadio
LatLng home = new LatLng(3.429862, -76.541336);
dato=getResources().getString(R.string.estadio);
mMap.addMarker(new MarkerOptions().position(home).title(dato)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.estadio)));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(home, 13));
//Sebastian Belalcazar
LatLng home1 = new LatLng(3.449151, -76.545185);
dato1=getResources().getString(R.string.sebas);
mMap.addMarker(new MarkerOptions().position(home1).title(dato1)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.sebastian)));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(home1, 13));
//Cristo Rey
LatLng home2 = new LatLng(3.435855, -76.564840);
dato2=getResources().getString(R.string.rey);
mMap.addMarker(new MarkerOptions().position(home2).title(dato2)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.cristo)));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(home2, 13));
//Tres cruces
LatLng home3 = new LatLng(3.467800, -76.545473);
mMap.addMarker(new MarkerOptions().position(home3).title(getResources().getString(R.string.cruces))
.icon(BitmapDescriptorFactory.fromResource(R.drawable.tres)));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(home3, 13));
//Plaza de Caicedo
LatLng home5 = new LatLng( 3.451864, -76.532479);
dato3=getResources().getString(R.string.plaza);
dato4="-" + getResources().getString(R.string.caicedo);
dato5="-" + getResources().getString(R.string.pedro);
dato6="-" + getResources().getString(R.string.palacio);
mMap.addMarker(new MarkerOptions().position(home5).title(dato3)
.snippet(dato4 + "\n" +
dato5 + "\n" +
dato6)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.plaza)));
mapa.moveCamera(CameraUpdateFactory.newLatLngZoom(home5, 13));
You need to set an algorithm so the clusters don't align in a grid, thus becoming more precise.
NonHierarchicalDistanceBasedAlgorithm<ClusterItem> algo = new NonHierarchicalDistanceBasedAlgorithm<>();
mClusterManager.setAlgorithm(algo);
//If that isn't enough you can change the latlng
Collection<ClusterItem> col = algo.getItems();
for (ClusterItem clusterItem : col) {
clusterItem.getPosition().latitude = yourNewLatitude;
clusterItem.getPosition().longitude = yourNewLongitude;
}
First of all my marker won't show up. But if it did then how would I keep it moving? I'm tracking a satellite. Iv'e done research but all i've found were folks using JSON arrays on their maps. However I have an object that needs to update across the map
I'm using a json OBJECT. Please don't give me links unless you are absolutely sure you know it can apply to my situation. Can anyone help?
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private LocationManager locationManager;
private GoogleMap mMap;
JSONParser jsonparser = new JSONParser();
private CameraPosition cameraPosition;
private GoogleMap googleMap;
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
private GoogleApiClient client;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(map);
List<MarkerOptions> markerOptions = new ArrayList<>();
Bitmap.Config conf = Bitmap.Config.ARGB_8888;
Bitmap bmp = Bitmap.createBitmap(200, 50, conf);
Canvas canvas = new Canvas(bmp);
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
#Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
}
public void animateMarker(final Marker marker, final LatLng toPosition,
final boolean hideMarker) {
MapFragment mapFragment = new MapFragment();
mapFragment.getMapAsync(this);
jobj = jsonparser.makeHttpRequest("http://api.wheretheiss.at/v1/satellites/25544");
try {
String lati = "latitude : " + jobj.getDouble("latitude");
} catch (JSONException e) {
e.printStackTrace();
}
try {
String longit = "longitude : " + jobj.getDouble("longitude");
} catch (JSONException e) {
e.printStackTrace();
}
final Handler handler = new Handler() {
};
final long start = SystemClock.uptimeMillis();
Projection proj = mMap.getProjection();
Point startPoint = proj.toScreenLocation(marker.getPosition());
final LatLng startLatLng = proj.fromScreenLocation(startPoint);
final long duration = 500;
final Interpolator interpolator = new LinearInterpolator();
handler.post(new Runnable() {
#Override
public void run() {
jobj = jsonparser.makeHttpRequest("http://api.wheretheiss.at/v1/satellites/25544");
try {
Double longit = jobj.getDouble("longitude");
Double lat = jobj.getDouble("latitude");
marker.setTitle("ISS");
marker.showInfoWindow();
marker.setPosition(new LatLng(lat, longit));
CameraUpdate center= CameraUpdateFactory.newLatLng(new LatLng(lat, longit));
CameraUpdate zoom = CameraUpdateFactory.newLatLngZoom(new LatLng(lat, longit),3);
googleMap.animateCamera(center);
googleMap.animateCamera(zoom);
} catch (JSONException e) {
e.printStackTrace();
}
long elapsed = SystemClock.uptimeMillis() - start;
float t = interpolator.getInterpolation((float) elapsed
/ duration);
if (t < 1.0) {
// Post again 16ms later.
handler.postDelayed(this, 16);
} else {
if (hideMarker) {
marker.setVisible(false);
} else {
marker.setVisible(true);
}
}
}
});
}
public void onLocationChanged(Location location) {
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(location.getLatitude(), location.getLongitude()), 17));
}
}
First of all, it seems like you forgot add your marker to map. I didn't see this code in your activity.
Secondly, there is an example of working method to move markers on the google map, developed by guys from google.
#TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
static void animateMarkerToICS(Marker marker, LatLng finalPosition, final LatLngInterpolator latLngInterpolator) {
TypeEvaluator<LatLng> typeEvaluator = new TypeEvaluator<LatLng>() {
#Override
public LatLng evaluate(float fraction, LatLng startValue, LatLng endValue) {
return latLngInterpolator.interpolate(fraction, startValue, endValue);
}
};
Property<Marker, LatLng> property = Property.of(Marker.class, LatLng.class, "position");
ObjectAnimator animator = ObjectAnimator.ofObject(marker, property, typeEvaluator, finalPosition);
animator.setDuration(3000);
animator.start();
}
And interpolator:
public interface LatLngInterpolator {
public LatLng interpolate(float fraction, LatLng a, LatLng b);
public class Linear implements LatLngInterpolator {
#Override
public LatLng interpolate(float fraction, LatLng a, LatLng b) {
double lat = (b.latitude - a.latitude) * fraction + a.latitude;
double lng = (b.longitude - a.longitude) * fraction + a.longitude;
return new LatLng(lat, lng);
}
}
}
More information you can find there
There are latitude and longitude of two place is given.This is my map activity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
#Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// double array [] = {44.968046 ,-94.420307 ,44.33328,-89.132008, 33.755787,-116.359998,33.844843,-116.54911 ,44.92057 ,-93.44786};
// Add a marker in Sydney and move the camera
double lat1 = 23.781388 ;
double lon1 = 90.425500 ;
double lat2 = 23.780270 ;
double lon2 = 23.780270 ;
LatLng place1 = new LatLng( lat1, lon1);
LatLng place2 = new LatLng( lat2, lon2);
mMap.addMarker(new MarkerOptions().position(place1).title("Marker in Pran RFL"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(place1));
mMap.addMarker(new MarkerOptions().position(place2).title("Marker in Gulshan"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(place2));
}
I want to draw a path between this couple of latitude and longitude.How Can I do it?
You have to add PolyLineOptions and add new LatLng() try this code
PolylineOptions options = new PolylineOptions();
options.color( Color.parseColor( "#CC0000FF" ) );
options.width( 5 );
options.visible( true );
options.add( new LatLng( lat1 ,lon1) );
options.add( new LatLng( lat2 ,lon2) );
mMap.addPolyline( options );
I am having trouble using the loactionListener in eclipse for android. I have been googling for a while now an I can't seem to see why this shouldn't work. The only thing I can think of is that maybe it is because my testing device has no sim. (the internet is provided via wifi).
I have used this as a reference and still, nothing.
Could anyone help me with this problem.
here is the relevant parts of my activity:
public class MainMenu extends Activity implements LocationListener{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_menu);
theMap = ((MapFragment)getFragmentManager().findFragmentById(R.id.the_map)).getMap();
theMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
locMan = (LocationManager)getSystemService(LOCATION_SERVICE);
}
#Override
public void onLocationChanged(Location location) {
final Double lat = location.getLatitude();
final Double lng = location.getLongitude();
LatLng lastLatLng = new LatLng(lat, lng);
String title = getString(new StringLang().textSet(userLang,"marker_title"));
String snippit = getString(new StringLang().textSet(userLang,"marker_snip"));
if(userMarker!=null) userMarker.remove();
userMarker = theMap.addMarker(new MarkerOptions()
.position(lastLatLng)
.title(title)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher))
.snippet(snippit));
reverseGeoCode(lat, lng);
}
}
I was using a different method to display my location on the map, which worked well but it never updated. It always showed my location at the last place I used the GPS, which turns out was 60mile accross the country. I can see this is working but is there a better way of doing this.
Old method:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_menu);
if(findViewById(R.id.the_map) != null){
//map has loaded continue
theMap = ((MapFragment)getFragmentManager().findFragmentById(R.id.the_map)).getMap();
theMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
locMan = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
android.location.Location lastLoc = locMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
LatLng lastLatLng ;
if(lastLoc == null){
/* Use the LocationManager class to obtain GPS locations */
double latitude = 0;
double longitude = 0;
lastLatLng = new LatLng(latitude, longitude);
lat = latitude;
lng = longitude;
String title = getString(new StringLang().textSet(userLang,"marker_title"));
String snippit = getString(new StringLang().textSet(userLang,"marker_snip"));
if(userMarker!=null) userMarker.remove();
userMarker = theMap.addMarker(new MarkerOptions()
.position(lastLatLng)
.title(title)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.your_loc_icon))
.snippet(snippit));
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(lastLatLng) // Sets the center of the map to user position
.zoom(0) // Sets the zoom
.bearing(90) // Sets the orientation of the camera to east
.tilt(20) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
currentLoc = lastLatLng;
theMap.animateCamera (CameraUpdateFactory.newCameraPosition(cameraPosition), 3000, null);
final TextView geoTagText = (TextView)findViewById(R.id.text_geoTag);
geoTagText.setText("We cannot find your current location, please check your settings.");
}else{
double latitude = lastLoc.getLatitude();
double longitude = lastLoc.getLongitude();
lastLatLng = new LatLng(latitude, longitude);
lat = latitude;
lng = longitude;
animateMap(lastLatLng);
}
}else{
theMap = ((MapFragment)getFragmentManager().findFragmentById(R.id.the_map)).getMap();
theMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
locMan = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
android.location.Location lastLoc = locMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
LatLng lastLatLng;
double latitude = lastLoc.getLatitude();
double longitude = lastLoc.getLongitude();
lastLatLng = new LatLng(latitude, longitude);
lat = latitude;
lng = longitude;
animateMap(lastLatLng);
//no map to load
}
}
#Override
public void onLocationChanged(Location location) {
final Double lat = location.getLatitude();
final Double lng = location.getLongitude();
LatLng lastLatLng = new LatLng(lat, lng);
String title = getString(new StringLang().textSet(userLang,"marker_title"));
String snippit = getString(new StringLang().textSet(userLang,"marker_snip"));
if(userMarker!=null) userMarker.remove();
userMarker = theMap.addMarker(new MarkerOptions()
.position(lastLatLng)
.title(title)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher))
.snippet(snippit));
}
it would also be useful to add that there is button to relocate the user manually if they want.
reLocBtn.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View arg0) {
if(menuActive == true){
playSound();
LocationManager loc = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
android.location.Location gpsLoc = (Location) loc.getLastKnownLocation(LocationManager.GPS_PROVIDER);
double lat = gpsLoc.getLatitude();
double lng = gpsLoc.getLongitude();
LatLng lastLatLng = new LatLng(lat, lng);
animateMap(lastLatLng);
}
}
});
I'm not to sure why either method doesn't update, but the second method seams to work better on first load.
You don't appear to be using requestLocationUpdates() anywhere. In that method you pass a LocationListener object that it then calls for location updates.
i.e. in your case:
locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
locMan.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
If you are using Google Maps API v2, you can do it using that, for example:
private GoogleMap.OnMyLocationChangeListener myLocationChangeListener = new GoogleMap.OnMyLocationChangeListener() {
#Override
public void onMyLocationChange(Location location) {
LatLng loc = new LatLng(location.getLatitude(), location.getLongitude());
mMarker = mMap.addMarker(new MarkerOptions().position(loc));
if(mMap != null){
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(loc, 16.0f));
}
}
};
and then set the listener for the map:
mMap.setOnMyLocationChangeListener(myLocationChangeListener);
This will get called when the map first finds the location.
No need for LocationService or LocationManager at all.