Need help regarding placement of map marker - android

I need your quick assistance for the problem stated below
In my android application I show a marker on specific location.
Here is my code
double latitude = Double.parseDouble(this.latitude);
double longitude = Double.parseDouble(this.longitude);
int latitudeE6 = (int) (latitude * 1e6);
int longitudeE6 = (int) (longitude * 1e6);
Log.i("Latitude","String = "+this.latitude+",Double = "+latitude+", int = "+latitudeE6);
Log.i("Longitude","String = "+this.longitude+",Double = "+longitude+", int = "+longitudeE6);
GeoPoint point = new GeoPoint(latitudeE6, longitudeE6);
Log.i("Point a", ""+point.getLatitudeE6()+","+point.getLongitudeE6());
OverlayItem overlay = new OverlayItem(point, title, detail);
Drawable drawable = mapView.getContext().getResources().getDrawable(
R.drawable.pin);
HelloOverlayItem helloOverLay = new HelloOverlayItem(drawable, this);
Log.i("Point b", ""+point.getLatitudeE6()+","+point.getLongitudeE6());
helloOverLay.addOverlay(overlay);
mapView.getOverlays().add(helloOverLay);
MapController controller = mapView.getController();
Log.i("Point c", ""+point.getLatitudeE6()+","+point.getLongitudeE6());
controller.animateTo(point);
controller.setCenter(point);
controller.setZoom(10);
I can get proper location integers in "Point C" log entry, which is not 0,0 (some where near London) But in map it always show me on 0,0 how can it be possible?? How to get rid of this??

I can't say that it's surely an answer or just a work around until it create some bug. But calling mapView.invalidate() worked. I have added this line exactly after mapView.getOverlays().add(helloOverLay); And it worked.

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

few locations not showing up on google map

I have list of stores and when i click on any one depending on their latitude and longitude values which i get from a web server i show them on the map. some of them show up but some wont...i know this is not a good question....but i am just expecting if someone who might have experienced the same problem might help.
here is the code:
Double Storelat = (FeedListViewActivity.lat);
Double Storelng = (FeedListViewActivity.lng);
storeLocation = new GeoPoint((int) (Storelat * 1E6), (int) (Storelng * 1E6));
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
super.draw(canvas, mapView, shadow);
Point locationPoint1 = new Point();
Projection projection1 = mapView.getProjection();
projection1.toPixels(storeLocation, locationPoint1);
Paint containerPaint = new Paint();
containerPaint.setAntiAlias(true);
int containerX1 = locationPoint1.x;
int containerY1 = locationPoint1.y;
if (shadow) {
containerX1 += CONTAINER_SHADOW_OFFSET;
containerY1 += CONTAINER_SHADOW_OFFSET;
containerPaint.setARGB(90, 0, 0, 0);
canvas.drawCircle(containerX1, containerY1, CONTAINER_RADIUS,
containerPaint);
} else {
containerPaint.setColor(Color.RED);
canvas.drawCircle(containerX1, containerY1, CONTAINER_RADIUS,
containerPaint);
}
}
and these are the values i get from the webserver:
working:
lat = 18.5170002
lng = 73.858078
not working:
lat = 18.618679
lng = 73.8037491
your answer is in your question itself
working:
lat = 18.5170002 lng = 73.858078
not working:
lat = 18.618679 lng = 73.8037491
as per above provided thing you can see the precision difference i have also faced the same problem be 6 months, and i have made that 6 precision to 8 precision and was working well then.
if you pass 18.618679 then it will treat it as 0.18618679 for confirmation try to zoom out up-to level 2 or 3 you will get your point at unexpected place.

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

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

MyLocationOverlay problem

private void initMyLocation() {
myLocOverlay = new MyLocationOverlay(this, myMap);
myLocOverlay.enableCompass();
myLocOverlay.enableMyLocation();
myMap.getOverlays().add(myLocOverlay);
if (myLocOverlay == null)
{
assignFirstLoc();
}
if (myLocOverlay != null)
{
Log.e("error","1");
p = new GeoPoint((int) (myLocOverlay.getMyLocation().getLatitudeE6()), (int) (myLocOverlay.getMyLocation().getLongitudeE6()));
mc = myMap.getController();
mc.animateTo(p);
mc.setCenter(p);
}
I saw "error 1" message in the logcat but after that I took an null pointer exception I dont know why, I believe I check myLocOverlay is null or not with "if" block.. Any suggesstions?
Edit:
This is my assignedGFirstLoc method that assigned the firtst values:
private void assignFirstLoc()
{
final String coordinates[] = {"41.00527", "28.97696"};
double lat2 = Double.parseDouble(coordinates[0]);
double lng2 = Double.parseDouble(coordinates[1]);
p = new GeoPoint((int) (lat2 * 1E6), (int) (lng2 * 1E6));
myMap.getController().setZoom(16);
myMap.getController().animateTo(p);
myMap.getController().setCenter(p);
}
MyLocationOverlay can only be used to show a location coming from sensors.
You cannot set it.
You got a NullPointer because MyLocationOverlay.getMyLocation() returns null. Sensors didn't have the time to catch the geolocation yet.
If you want to show the location when the sensor got the data you can do this:
mMyLocationOverlay.runOnFirstFix(new Runnable() { public void run() {
mapView.getController().animateTo(mMyLocationOverlay.getMyLocation());
}});
If you want to display an item in an arbitray location (with latitude and longitude values) you need to implement your own version of ItemizedOverlay
You can find an exemple in the SDK documentation: Google Map View tutorial, Part2 AddingOverlayItem
If you just want to show an arbitrary location on the map, you don't need an overlay. just call your function and it will work:
private void initMyLocation() {
assignFirstLoc();
}
It looks like you are not passing any coordinates into GeoPoint. Unless it is somewhere else in your code. Something like this works
String coordinates[] = {"41.146064", "-80.642861"};
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));

Categories

Resources