Titanium JIRA Archive
Appcelerator Modules (MOD)

[MOD-2436] Ti.Map: Android - App crash with map when using v4.0.0+

GitHub Issuen/a
TypeBug
PriorityNone
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
ComponentsMap
Labelsn/a
ReporterHans Knöchel
AssigneeYordan Banev
Created2018-06-21T09:42:02.000+0000
Updated2018-06-28T10:22:22.000+0000

Description

From the community: This code is used to remove the current setted pin on the map and put a new one where the user have tapped. When you update the ti.map module in crash the app. It happens on Android 7 and 8.
var Map = require('ti.map');
var mapview = null;
var circle = null;
var currentLatitude = null;
var currentLongitude = null;
var puntoEvento = null;
var currentAddress = null;

//Function fired from a view where map is
function setAnnotationOnLongPress(e){
   	/*
   	 * {"type":"longclick","source":{"compassEnabled":true,"animate":true,"annotations":[{"showInfoWindow":true,"pincolor":0,"longitude":9.7152357,"latitude":45.7138272,
   	 * "title":"Tua Posizione","subtitle":"Sblind","apiName":"Ti.Proxy","bubbleParent":true,"myid":1}],
   	 * "region":{"latitude":45.7138272,"longitude":9.7152357,"latitudeDelta":0.01,"longitudeDelta":0.01},
   	 * "mapType":1,"userLocation":false,"minZoomLevel":2,"zoom":15.627570152282715,"maxZoomLevel":21,"hiddenBehavior":4,"enabled":true,"visible":true,"touchEnabled":true,
   	 * "backgroundRepeat":false,"keepScreenOn":false,"children":[],"size":{"height":594,"width":360,"y":0,"x":0},"rect":{"absoluteX":0,"height":594,"width":360,"y":0,"absoluteY":0,"x":0},
   	 * "apiName":"Ti.Map","bubbleParent":true,"regionFit":true,"soundEffectsEnabled":true,"horizontalWrap":true,"_events":{"click":{}}},"map":{"compassEnabled":true,"animate":true,
   	 * "annotations":[{"showInfoWindow":true,"pincolor":0,"longitude":9.7152357,"latitude":45.7138272,"title":"Tua Posizione","subtitle":"Sblind","apiName":"Ti.Proxy","bubbleParent":true,"myid":1}],
   	 * "region":{"latitude":45.7138272,"longitude":9.7152357,"latitudeDelta":0.01,"longitudeDelta":0.01},"mapType":1,"userLocation":false,"minZoomLevel":2,"zoom":15.627570152282715,
   	 * "maxZoomLevel":21,"hiddenBehavior":4,"enabled":true,"visible":true,"touchEnabled":true,"backgroundRepeat":false,"keepScreenOn":false,"children":[],"size":{"height":594,"width":360,"y":0,"x":0},
   	 * "rect":{"absoluteX":0,"height":594,"width":360,"y":0,"absoluteY":0,"x":0},"apiName":"Ti.Map","bubbleParent":true,"regionFit":true,"soundEffectsEnabled":true,"horizontalWrap":true,
   	 * "_events":{"click":{}}},"cancelBubble":false,"longitude":9.713328257203102,"latitude":45.71091987188729,"bubbles":true}
   	 */
    currentLatitude = e.latitude;
    currentLongitude = e.longitude;
    getGoogleGeo();

    mapview.removeAnnotation(puntoEvento);
    //mapview.removeAllAnnotations();
    puntoEvento.latitude = e.latitude;
	puntoEvento.longitude = e.longitude;
	
	
	mapview.addAnnotation(puntoEvento);

	mapview.region = {
		latitude : e.latitude,
		longitude : e.longitude,
		latitudeDelta : 0.01,
		longitudeDelta : 0.01
	};

	if(OS_ANDROID)
		mapview.removeCircle(circle);
	else
		mapview.removeAllCircles();

	circle = Map.createCircle({
		center : {
			latitude : e.latitude,
			longitude : e.longitude
		},
		strokeWidth : 3,
		strokeColor : 'black',
		radius : parseInt(verticalSlider.value, 10), //1km
		fillColor : "#20FF0000"
	});
	mapview.addCircle(circle);
	
}

function loadMap(circleExtension) {
	puntoEvento = Map.createAnnotation({
		latitude : currentLatitude,
		longitude : currentLongitude,
		title : "Your position",
		subtitle : 'Sblind',
		pincolor : Map.ANNOTATION_RED,
		myid : 1 // Custom property to uniquely identify this annotation.
	});

	mapview = Map.createView({
		mapType : Map.NORMAL_TYPE,
		region : {
			latitude : currentLatitude,
			longitude : currentLongitude,
			latitudeDelta : 0.01,
			longitudeDelta : 0.01
		},
		animate : true,
		regionFit : true,
		userLocation : false,
		annotations : [puntoEvento]
	});

	circle = Map.createCircle({
		center : {
			latitude : currentLatitude,
			longitude : currentLongitude
		},
		strokeWidth : 3,
		strokeColor : 'black',
		radius : (_.isUndefined(circleExtension)) ? 50 : circleExtension, //1km
		fillColor : "#20FF0000"
	});
	mapview.addCircle(circle);

	$.mapContainer.add(mapview);
	// Handle click events on any annotations on this map.
	mapview.addEventListener('click', function(evt) {
		Ti.API.info("Clicked " + evt.clicksource + " on " + evt.latitude + "," + evt.longitude);
	});
	$.main.open();
}

function loadCoordinate(){
	disegnaControlli();
	if (Ti.Geolocation.locationServicesEnabled) {
	    Ti.Geolocation.setAccuracy(Ti.Geolocation.ACCURACY_BEST);//Ti.Geolocation.ACCURACY_BEST;

	    if(Titanium.Platform.osname != "android")
	       Ti.Geolocation.setDistanceFilter(10);
    	
    	Titanium.Geolocation.getCurrentPosition(function(e){//Funzione per posizione corrente
    		if(e.coords!=null){
    			Ti.API.info(JSON.stringify(e));
    			currentLatitude = e.coords.latitude;
    			currentLongitude = e.coords.longitude;
    			getGoogleGeo();
		    	loadMap();
	        }
     	});
	}
	else{
		_Utility.popUp(L('gps_disabilitato'), L('gps_disabilitato_msg'));
		currentLatitude = 45.7138565;
		currentLongitude = 9.7151823;
		getGoogleGeo();
    	loadMap();
	}
}

function openMap() {
	if(_.isNull(Alloy.Globals.mapObj)){
		if (!Titanium.Geolocation.hasLocationPermissions(Titanium.Geolocation.AUTHORIZATION_WHEN_IN_USE)) {
			Titanium.Geolocation.requestLocationPermissions(Titanium.Geolocation.AUTHORIZATION_WHEN_IN_USE, function(result) {
				if (result.success) {
					loadCoordinate();
				} else {
					_Utility.popUp(L("no_permessi_title"),L("no_permessi"));
				}
			});
		} else {
			loadCoordinate();
		}
	}
	else{
		Ti.API.info(JSON.stringify(Alloy.Globals.mapObj));
		currentLatitude = Alloy.Globals.mapObj.latitudine;
		currentLongitude = Alloy.Globals.mapObj.longitudine;
		
		getGoogleGeo();
		
		disegnaControlli(Alloy.Globals.mapObj.raggio);
		$.label.text = Alloy.Globals.mapObj.raggio;
		loadMap(Alloy.Globals.mapObj.raggio);
	}
}

var tentativiTimeout = 3;
var tentativiGoogle = 5;
var pausaTraTentativi = 200;//ms
var timeoutRichiesta = 5000;//ms

function getGoogleGeo() {
	if (Titanium.Network.online) {
		var addrUrl = "http://maps.googleapis.com/maps/api/geocode/json?sensor=true&latlng=" + currentLatitude + "," + currentLongitude;
		/* web-service call */
		Ti.API.info(addrUrl);
		var addrReq = Titanium.Network.createHTTPClient();
		addrReq.setTimeout(timeoutRichiesta);
		addrReq.open("GET", addrUrl);

		addrReq.onerror = function() {
			if(tentativiTimeout > 0){ // riprovo a fare la richiesta
				tentativiTimeout--;
				getGoogleGeo();
			}
			else
				currentAddress = currentLatitude + "," + currentLongitude;
		};
		addrReq.onload = function() {
			var response = JSON.parse(this.responseText);
			var street,
			    num,
			    city,
			    province,
			    cap,
			    country;
			if (response.status == "OK") {
				var resLen = response.results[0].address_components.length;
				for (var i = 0; i < resLen; i++) {
					switch (response.results[0].address_components[i].types[0]) {
					case "street_number":
						num = response.results[0].address_components[i].long_name;
						break;
					case "route":
						street = response.results[0].address_components[i].long_name;
						break;
					case "locality":
						city = response.results[0].address_components[i].long_name;
						break;
					case "administrative_area_level_2":
						province = response.results[0].address_components[i].short_name;
						break;
					case "postal_code":
						cap = response.results[0].address_components[i].long_name;
						break;
					case "country":
						country = response.results[0].address_components[i].long_name;
						break;
					}
				}
			
				currentAddress = street + "," + num + "," + cap + "," + city + "," + province + "," + country;
				Ti.API.info(currentAddress);
			}
			else{
				if(tentativiGoogle > 0){ // se non ho esaurito i tentativi aspetto un attimo e riprovo
					tentativiGoogle--;
					setTimeout(function(e){getGoogleGeo();}, pausaTraTentativi);
				}
				else
					currentAddress = currentLatitude + "," + currentLongitude;
			}
		
		};
		addrReq.send(null);
	}
	else{
		currentAddress = currentLatitude + "," + currentLongitude;
	}
}

openMap();
}

Comments

  1. Yordan Banev 2018-06-21

    [~Pietro], I believe you reported the issue in github. I tried to run the application, but I got the the point where the code is looking for Alloy.Globals.mapObj which is undefined. Is it defined outside this code sample?
  2. Pietro Granati 2018-06-21

    Yes is a property that comes from another page, I save the current settings of the map so if you close it and want to modify it before save its avaiable: Alloy.Globals.mapObj = { latitudine: currentLatitude, longitudine: currentLongitude, indirizzo: inidirizzoCorrente, raggio: parseInt(verticalSlider.value, 10) };
  3. Yordan Banev 2018-06-21

    Would you be able to provide a sample that runs as a standalone application and reproduces the issue for me in order to investigate it ? An archive of a whole project would do, too.
  4. Pietro Granati 2018-06-21

    Unfortunately I don't have authorization right know to send the full project. I have a map with a pin set on it and a circle around it. On longpress that pin should remove and set a new one on the point longpressed by he user. this procedure cause app to crash so i back to v4.0.0
  5. Yordan Banev 2018-06-21

    Can you share a console error log?
  6. Pietro Granati 2018-06-21

    It's too lo, I dngIon't know how to attach te firs thit lines: [INFO] : art: art/runtime/thread.cc:1665] Throwing new exception 'Attempt to invoke virtual method 'java.lang.Object org.appcelerator.kroll.KrollDict.get(java.lang.Object)' on a null object reference' with unexpected pending exception: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object org.appcelerator.kroll.KrollDict.get(java.lang.Object)' on a null object reference [INFO] : art: art/runtime/thread.cc:1665] at void org.appcelerator.kroll.KrollProxy.onPropertyChanged(java.lang.String, java.lang.Object) (KrollProxy.java:1056) [INFO] : art: art/runtime/thread.cc:1665] at void ti.map.AnnotationProxy.onPropertyChanged(java.lang.String, java.lang.Object) (AnnotationProxy.java:389) [INFO] : art: art/runtime/thread.cc:1665] at boolean org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(long, java.lang.Object, long, java.lang.String, java.lang.Object, boolean, boolean, int, java.lang.String) (V8Object.java:-2) [INFO] : art: art/runtime/thread.cc:1665] at boolean org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(org.appcelerator.kroll.KrollObject, java.lang.String, java.lang.Object, boolean, boolean, int, java.lang.String) (V8Object.java:63) [INFO] : art: art/runtime/thread.cc:1665] at boolean org.appcelerator.kroll.KrollProxy.doFireEvent(java.lang.String, java.lang.Object) (KrollProxy.java:962) [INFO] : art: art/runtime/thread.cc:1665] at boolean org.appcelerator.kroll.KrollProxy.handleMessage(android.os.Message) (KrollProxy.java:1186) [INFO] : art: art/runtime/thread.cc:1665] at boolean org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(android.os.Message) (TiViewProxy.java:394) [INFO] : art: art/runtime/thread.cc:1665] at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:98) [INFO] : art: art/runtime/thread.cc:1665] at void android.os.Looper.loop() (Looper.java:154) [INFO] : art: art/runtime/thread.cc:1665] at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6311) [INFO] : art: art/runtime/thread.cc:1665] at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2) [INFO] : art: art/runtime/thread.cc:1665] at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:872) [INFO] : art: art/runtime/thread.cc:1665] at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:762) [INFO] : art: art/runtime/thread.cc:1665] [INFO] : art: art/runtime/runtime.cc:403] Runtime aborting... [INFO] : art: art/runtime/runtime.cc:403] Aborting thread: [INFO] : art: art/runtime/runtime.cc:403] "main" prio=5 tid=1 Runnable [INFO] : art: art/runtime/runtime.cc:403] | group="" sCount=0 dsCount=0 obj=0x75acaf78 self=0xad404400 [INFO] : art: art/runtime/runtime.cc:403] | sysTid=6423 nice=1 cgrp=default sched=0/0 handle=0xb02cb534 [INFO] : art: art/runtime/runtime.cc:403] | state=R schedstat=( 0 0 0 ) utm=609 stm=105 core=2 HZ=100 [INFO] : art: art/runtime/runtime.cc:403] | stack=0xbe741000-0xbe743000 stackSize=8MB [INFO] : art: art/runtime/runtime.cc:403] | held mutexes= "abort lock" "mutator lock"(shared held)
  7. Pietro Granati 2018-06-21

    "It's too lo, I dngIon't know how to attach te firs thit lines:" damn mac keyboard it's: It's too long to paste, I don't know how to attach it, the first lines are:
  8. Yordan Banev 2018-06-21

    If you want you can use pastebin for all of it and share the link here.
  9. Pietro Granati 2018-06-21

    Oooh I forgot about pastebin https://pastebin.com/M3iwAm5s
  10. Yordan Banev 2018-06-22

    [~Pietro] I am unable to pin-point where the problem may be from the full log. Is there a chance you can reproduce the crash in a separate project doing the flow you described?

JSON Source