onLocationChanged call the onDraw method in my custom view
I have a MapImageViewer Activity class that has methods for checking the phones gps location. This activity then calls a custom view of mine called MapCanvas - where the constructor takes the latitude and longitude and then draws a circle to the corresponding pixels on an image of a map.
This works ok, but I am wondering how can I update and call the onDraw method every time the gps coordinates change? I know it needs to go in开发者_C百科 the onLocationChanged method..but i'm not sure how i can pass the new latitude and longitude values from there to my Custom View class.
What about sending lat/lon from the onLocationChanged()
method by using .sendBroadcast()
and handle them inside your View class with a BroadcastReceiver
?
Alternatively you could use a callback method from the LocationListener like shown in this post.
Call the view's invalidate()
method every time you get new coordinates (or postInvalidate()
if the locationListener is in a different thread from the UI thread)
精彩评论