Are the geopoint different for osmdroid and Android application? - android

I am using OsmDroid for my Android application. I am setting a IGeoPoint as follows
IGeoPoint point2 = new IGeoPoint() {
public int getLongitudeE6() {
return 51475022;
}
public int getLatitudeE6() {
return -300322;
}
};
mapController.animateTo(point2);
this took me to deep blue sea. Whereas when I use google.mapview and set geopoint in following way
myMapController.animateTo(new GeoPoint((int) (51.475022 * 1E6),
(int) (-0.300322 * 1E6)));
it takes me to where I want
What's wrong with osmdroid?

Why are you trying to create a constructor for an Interface?
The Osmdroid GeoPoint is a class which implements this interface. You just need to instantiate a GeoPoint, like this:
GeoPoint gPt = new GeoPoint(51500000, -150000); // latitude, longitude
Then pass this to your .animate()

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();

Android mapview geopoint difference emulator and device

i am getting data from gps provider using mylocation class. code is this:
MyLocation.LocationResult locationResult = new MyLocation.LocationResult() {
#Override
public void gotLocation(Location location) {
//Got the location!
// for phone
//currentLocation = new GeoPoint((int) (location.getLatitude() * 1000000),
// (int) (location.getLongitude() * 1000000));
// for emulator
currentLocation = new GeoPoint((int) (location.getLatitude()),
(int) (location.getLongitude()));
doSomething();
}
};
MyLocation myLocation = new MyLocation();
myLocation.getLocation(this, locationResult);
when i use the app in emulator(2.3.3) it shows the correct location without multiplying anything.
but when i use it in a device(4.0) lat and lon need to multiplied with 1000000. i couldn't find why. i don't think its because of the version of android. anyone have any idea?
Because the MapView uses microdegress for its units so you need to multiply by 1e6. Otherwise you show up off the coast of Africa - basically lat long of approximately 0,0
From the documentation on GeoPoint:
An immutable class representing a pair of latitude and longitude, stored as integer numbers of microdegrees.
Don't know why the emulator is working - it shouldn't.

How to properly use drawMyLocation

I am trying to show the users current location with the default blue dot in android. In my maps page I also have a layout that shows different points of interest. Im having trouble figuring out what to put for some of the variables and was wondering if someone could help me out.
This is what I'm using so far to show my location.
Location location = locationManager
.getLastKnownLocation(bestProvider);
try {
GeoPoint myPoint2 = new GeoPoint(
(int) (location.getLatitude() * 1E6),
(int) (location.getLongitude() * 1E6));
newoverlay.drawMyLocation(null, mapView, location, myPoint2,
1000);
mapOverlays.add(newoverlay);
} catch (NullPointerException e) {
GeoPoint myPoint2 = new GeoPoint((int) (-1 * 1E6),
(int) (-1 * 1E6));
**newoverlay.drawMyLocation(null, mapView, location, myPoint2,
1000);**
mapOverlays.add(newoverlay);
}
I'm not sure what to put as the Canvas so I placed it with null so that it would compile. I'm using the location from a location Manager and I have my geopoint from the location variable. I'm also unsure what the "when" parameter is supposed to be.
I was also wondering how the blue bubble knows to move with the person, does the picture update every x milliseconds depending on the "when" parameter?
So far the app isn't crashing, but it is also not showing the blue dot at any location.
I'm sure I just need help with finding what the canvas parameter should be.
Thanks
try this way in your map activity
class CurOverlay extends Overlay {
private GeoPoint pointToDraw;
public void setPointToDraw(GeoPoint point) {
pointToDraw = point;
}
public GeoPoint getPointToDraw() {
return pointToDraw;
}
#Override
public boolean draw(Canvas canvas, MapView curmapView, boolean shadow,
long when) {
super.draw(canvas, curmapView, shadow);
// convert point to pixels
Point screenPts = new Point();
curmapView.getProjection().toPixels(pointToDraw, screenPts);
// add marker
Bitmap bmp = BitmapFactory.decodeResource(getResources(),
R.drawable.pinsource);
canvas.drawBitmap(bmp, screenPts.x - 28, screenPts.y - 48, null);
return true;
}
}
i hope this will work for you.

Problem generating GeoPoint in Android

I'm trying to create GeoPoints, but I couldn't so far.
double latitudeUpperLeft = -34.567645;
double longitudeUpperLeft = -58.497734;
double latitudeBottomRight = -34.62558;
double longitudeBottomRight = -58.42495;
GeoPoint geoPointUpperLeft = calculateGeoPoint(latitudeUpperLeft, longitudeUpperLeft);
GeoPoint geoPointBottomRight = calculateGeoPoint(latitudeBottomRight, longitudeBottomRight);
This is the helper method:
public static GeoPoint calculateGeoPoint(double latitude, double longitude) {
Double latE6 = latitude * 1E6;
Double lngE6 = longitude * 1E6;
return new GeoPoint(latE6.intValue(), lngE6.intValue());
}
I'm getting an InvocationTargetException on the return of the helper method, What could be wrong?
Thanks. Guillermo.
can you tell me if this works.
public static GeoPoint calculateGeoPoint(double latitude, double longitude) {
return new GeoPoint((int)(latitude * 1E6), (int)(longitude * 1E6));
}
I've found the answer in the anddev.org forum.
The problem was in the manifest, somehow it was missing this entry:
<uses-library android:name="com.google.android.maps" />
After adding it, it started to work.
If you want to use Directly GeoPoint .You will follow the steps:
1)First you have data(Location) in degree formate.
2)By the Equation you have to multiply it by 1000000
3)now ,you have particular GEO POINT Location .
Like here ;if I have location like : Latitude:23.0395677 and Longitude:72.5660045° So, your GeoPoint(23039568,72566045);
You get the Perfect Location for it.

How to set mapview to not show my current location?

how to coding to set mapview don't show the current location
now it's not show on emulater but when I try to install on my mobile , the current location sigh will show
What should I do?
public static int getCoordinateE6(double coordinate) {
return (int) (coordinate * 1E6);
}
GeoPoint geoPoint = new GeoPoint(
GoogleMapServiceHelper.getCoordinateE6(latitude),
GoogleMapServiceHelper.getCoordinateE6(longitude));
getMapView().getController().animateTo(geoPoint);

Categories

Resources