Marking Current Location on Map, Android

萝らか妹 提交于 2019-12-03 00:33:29

the way you construct the MyLocationOverlay might have some problem.

MyLocationOverlay mylocationOverlay = new MyLocationOverlay(this, mapView);

according to the google code api you need to pass a context and a mapview param.

and then put these code after that

mylocationOverlay.enableMyLocation();
mapView.getOverlays().add(locationOverlay);

also put

mylocationOverlay.enableMyLocation(); in the onResume() method

Hope this could help you.

The GeoPoint "p" in the MyLocationOverlay is null. When you replay "GeoPoint initGeoPoint" with "p" you can solve this problem.

This is something which might help you in sloving your byg:

http://code.google.com/p/android/issues/detail?id=2035

In your logs look at this line 01-19 05:31:46.541: ERROR/AndroidRuntime(770): at pro.googlemapp.LocationActivity$MyLocationOverlay.draw(LocationActivity.java:101)

This refers to the GeoPoint p. At the beginning you set the value of p to null (as "asdf" says) and never change its value to a GeoPoint and that is why you get java.lang.NullPointerException.

For example you can set the value of p like this: p = new GeoPoint(19240000,-99120000); and of course this must happen before this line mapView.getProjection().toPixels(p, myScreenCoords); of your code.

Good luck

This is because Geopoint p value is null in class MyLocationListener. So when you called mapView.getProjection().toPixels(p, myScreenCoords); because p is null it is unable to convert toPixels and throws Exception. You can overcome on this by just declare your GeoPoint p as static in your LocationActivity.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!