Give double value to Geopoint in GoogleMap overlays - android

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

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

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.

Unable to find a Location Dynamically in Google-Map

I am facing a problem with the google map search. I have mad a app through which i can see a location in google map on my emulator which is set in the code as:
int lat = (int)(22.3666667*1000000);
int lng = (int)(91.8000000*1000000);
GeoPoint pt = new GeoPoint(lat,lng);
This works fine.
Now i want to search a location dynamically i.e. i have a editbox(Location_For_Search) and a button(Find_Location_Button). So when i write some location in editbox and press the button then it will show the location in google map with a marker on location. How can i do this?
Please any one help me.
With best wishes
Md. Fazla Rabbi
Use the geocoder:
Geocoder geo = new Geocoder(this);
List<Address> addr;
try
{
addr = coder.getFromLocationName(yourEditTextaddr, 10);
Address loc = addr.get(0);
loc.getLatitude();
loc.getLongitude();
point = new GeoPoint((int) (loc.getLatitude() * 1E6),
(int) (loc.getLongitude() * 1E6));
return point;
}

How can I to centered my location with mylocationoverlay?

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

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).

Categories

Resources