How can I to centered my location with mylocationoverlay? - android

I can take my location with myLocationOverlay easily, and I want to set as a center of my location, I tried map controller:
MapController mc = myMap.getController();
mc.animateTo();
mc.setCenter(myLocOverlay.getMyLocation());
these code didnt work so I changed
p = new GeoPoint((int) (myLocOverlay.getMyLocation().getLatitudeE6()), (int) (myLocOverlay.getMyLocation().getLongitudeE6()));
mc.setCenter(p);
But there is no good news. I took null pointer exception then I assigned new location before myLocationOverlay() but its not working.. Thanks for advance..

The animateTo can be used for this,
GeoPoint point = this.currentLocationOverlay.getMyLocation();
if(point==null)
return;
//center map on that geopoint
mc.animateTo(point);

Related

MapView start position

Good afternoon,
When i'm starting my application, the mapview is showed like you can see in the follow picture :
but i would like to start the mapview with some zoom in some point, something similar to this :
Which method i need to use?
Thanks in advance.
You add a zoom level to the map controller:
mapView.getController().setZoom(17); // an int that suits you
Read more about zoom levels here: https://developers.google.com/maps/documentation/staticmaps/#Zoomlevels
To set center you can use:
mapView.getController().setCenter(new GeoPoint(latitude,longitude));
set -
mapView.setStreetView(true);
mapView.getController().setZoom(17); // an int that suits you
mapView.getController().setCenter(new GeoPoint(latitude,longitude));
This is the solution.
for displaying egypt use it-
String coordinates[] = {"18.352566007", "73.78921587"};//here you can set geopoints of egypt
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
p = new GeoPoint(
(int) (lat * 1E6),
(int) (lng * 1E6));//p is GeoPoint
mc.animateTo(p);
mc.setZoom(17);
mapView.invalidate();

Remove pin mapview?

I am working on GoogleMap with MapView.Part of my project i am touching on the map and i am adding pin.My question is i want to remove pin which can added before. How can i do that i want to give Geopoint to the function.
Can anybody give me suggestion?
This is my code:`
public void AddPoint(Drawable drawable, MapView mapView, MotionEvent motionEvent) {
p = mapView.getProjection().fromPixels(
(int) motionEvent.getX(),
(int) motionEvent.getY()-50);
final MapController mc = mapView.getController();
mc.setZoom(16);
CustomItemizedOverlay<CustomOverlayItem> itemizedOverlay = new CustomItemizedOverlay<CustomOverlayItem>(drawable, mapView);
itemizedOverlay.addOverlay(new CustomOverlayItem(p,"","",""));
mapView.getOverlays().add(itemizedOverlay);
mc.animateTo(p);
mapView.invalidate();
}`
mapView.getOverlays().clear();
Call marker.remove(). To get the reference to the marker, you need to save the markers to a List when you create them, and then you can iterate over the List to find the ones you want.

Map values on Google map android

If there are values for Longitude and latitude how to map these values on GoogleMaps.Please give me links to this..
Ex: Longitude:12.93434334 Latitude:144.12121212
How to map these values on google map and get the position
If you mean to set/display map at particular coordinates you need to get MapController from MapView and set/animate to center you wish.
MapView view = (MapView)findViewById(id);
MapController controller = view.getController();
GeoPoint gp = new GeoPoint(lat, lon);
controller.setCenter(gp);
// controller.animateTo(gp); alternatively...

MyLocationOverlay doesn't appear

when I call this method the blue dot is not appearing on the map, until i send location from ddms,
then suddenly it appears.
private void findMyLocation(final Location location){
final MyLocationOverlay myLocationOverlay = new MyLocationOverlay(this, mapView);
myLocationOverlay.enableMyLocation();
myLocationOverlay.enableCompass();
final GeoPoint point = new GeoPoint((int) (location.getLatitude() * 1E6),
(int) (location.getLongitude() * 1E6));
controller.animateTo(point);
controller.setCenter(point);
mapView.getOverlays().add(myLocationOverlay);
mapView.postInvalidate();
}
how can i show that blue dot right after calling this method?
thanks a lot.
how can i show that blue dot right after calling this method?
You can't.
MyLocationOverlay, as its name suggests, shows the user's location. If the device/emulator does not know the user's location, it cannot show it.
In the case of the device, it will not show the user's location until it has determined said location (e.g., GPS).
In the case of the emulator, it will not show the user's location until it has determined said location (e.g., DDMS).

Give double value to Geopoint in GoogleMap overlays

I want to point to a Google map location using overlay. For this purpose latitude and longitude values will be assigned to a GeoPoint, but it only accepts int values.
How can I assign it a double value? Or is there another solution to point to an exact location?
point = new GeoPoint((int)t.getLati(),(int)t.getLongi())
Any help would be appreciated.
Since GeoPoint accepts latitudes and longitudes in microdegrees, simply create your point like so:
GeoPoint point = new GeoPoint((int)(latitude * 1e6),
(int)(longitude * 1e6));

Categories

Resources