Saturday 15 August 2015

Adding marker to google map from AsyncTask -


I have a very weird problem which is making me crazy to avoid blocking the main thread, I use the marker in my map Connect to AsyncTask. This is working fine in Nexus 4 with 4.2.2, but with the 3.2 or Galaxy Ace in tablets galaxy 2.3.7, this is giving me a tap pointer exception when map.addMarker () does. The error marker is for the operation because if I am creating a marker option in OnProgrssUpdate, then there is no error. I check that the object is not empty and it is not. Even I put a log D before the addMarker and the object is correct, but I get an error. Here you have the code:

  Map of the private class, asymcin AsyncTask and lt; Zero, Item, Zero & gt; {@ Override Safe Volume Doine Background (Zero ... Value) {int thickness = getResources () GetDisplayMetrics () Density dpi; (Int. Company ID: For companies) {Try {company company = DBC companies.com (company bank) LatLng pos = new wave long (company.getLatitude), Company. Galactidu ()); If (pos.latitude == 0 & amp; pos.longitude == 0) released; Subcategory subcategory = DBParameters.getSubcategory (db_path, GSSettings.DBCODE, Company .getSubcategoriesId () [0], Locale .getDefault () getLanguage ().); Bitmap bitmap; If (subcategory.getMarker () = null & amp;; & subcategory.getMarker () Length> gt; 1) bitmap = GSTools.getBitmapFromMDPI (subcategory.getMarker (), density); Else bitmap = GSTools.getBitmapFromMDPI (subcategory0.getMarker (), density); MarkerOptions markerOptions = New MarkerOptions (). Position (POS) .anchor (0, 1) .title (company.getName ()) .snippet (subcategory.getName ()) .icon (bitmapDescriptorFactory.fromBitmap (bitmap)); Item item = new item (marker option, company.getid); PublishProgress (item); } Hold (exception e) {}} return tap; } @ Override Protected Zero progress on the update (item ... value) {try {marker options marker option = value [0] .markerOptions; Log D. ("Marker", marker option .getTitle ()); // markerOptions = New MarkerOptions () //. Status (New LatLng (37.750,087, -0.8,48,522)) .anchor (0, 1) // .title ("TT ") // .icon (BitmapDescriptorFactory // .fromResource (R.drawable.ic_button_map)); Marker m = map.addMarker (marker option); HaspMap.put (m, value [0] .comapnyId); Log D. ("Marker", marker option .getTitle ()); } Hold (exception e) {log d. ("Marker", e.ostustring ()); } Super.onProgressUpdate (value); }}   

If I use the marker option then any ideas works ??

Thank you.

Try to use:

  mContext.runOnThread (new Runnable () {Public Zero Run () {// Your Marker Here Marker Meter = map.addMarker (markerOptions) add; haspMap.put (m, company.getId ()); log D. ("marker", marker option. GetTitle ());}});   

Instead of using the progress update mechanism to update your UI, MContext is your activity / reference

No comments:

Post a Comment