Hi All.
I am struggling to get my map to centre on an annotation after i have added it. It seems to work ok when i add annotations after geocoding and getting users current location.
But when i add annotations based on Lat/Lon saved in the database, it add the annotation but the map is offset a little which places the annotation at the bottom-right of the map? I have worked around this by setting a timeout of 500 on the $.map.location function which seems to have fixed my issue on my iPhone 5s but on my iPhone 4s its still not showing the annotation in the centre of the map?? Even with the fix, the map's original centre is offset from the annotation placing it in the bottom right and it then centres the map on the annotation after 500ms, which i can live with but its not working for smaller screens.
var addAnnotation = function(lat, lon, address){ // Set height to 200 (visible) as standard the map's height is 0 $.mapview.height = 200; // Set height to 0 (not visible) hide the image that was originally displayed $.productImgView.height = 0; // Remove existing annotations (if any) $.map.removeAllAnnotations(); // Add Annotation var yourLocation = Alloy.Globals.Map.createAnnotation({ pincolor: Alloy.Globals.Map.ANNOTATION_RED, title:"Your Location", subtitle: address.substring(0, 25)+'...', latitude: lat, longitude: lon }); // Add new annotation $.map.addAnnotation(yourLocation); $.map.selectAnnotation(yourLocation); // Centre Map (bypass the bug, which works on iPhone5 / iPhone 5s, but not smaller screens) setTimeout(function(){ $.map.location = {latitude: lat, longitude: lon,latitudeDelta: 0.01,longitudeDelta: 0.01}; },500); };