CLLocation does not have a Coordinates property - xamarin.ios

I am just working my way through the location services for the first time and everything appears to be working in that it correctly finds my location but I am having trouble extracting the coordinates.
The docs states that CLLocation has a "Coordinates" property and the compiler is happy with this piece of code. However at runtime the CLLocation only appears to return a string description.
I start the location manager
_locationManager = new CLLocationManager ();
_locationManager.DesiredAccuracy = 1000;
// handle the updated location method and update the UI
_locationManager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => {
UpdateLocation (e.Locations [e.Locations.Length - 1], _destinationLatitude, _destinationLongitude);
};
if (CLLocationManager.LocationServicesEnabled)
_locationManager.StartUpdatingLocation ();
The event fires correctly
static public void UpdateLocation (CLLocation current, Double destinationLat, Double destinationLng)
{
//Make the start pairing
string start = current.Coordinate.Latitude.ToString() + "," + current.Coordinate.Longitude.ToString();
//Make the destination pairing
string destination = destinationLat.ToString() + "," + destinationLng.ToString();
}
However the app just crashes out. Catching it on a breakpoint I see the following which only appears to have a description property that contains.
Description "<+50.58198902,-3.67661728> +/- 65.00m (speed -1.00 mps / course -1.00) # 25/07/2013 13:11:28 British…" string
I can obviously extract the lat/lng from this text field but I get the feeling I shouldn't need to do this. Any help appreciated.

I moved the exact same code into a different controller and it worked fine. The only difference between the two controllers was that the failing controller was using the monotouch dialog reflection api to bind the screen elements. I can't see why this would make any difference but it is the only difference between the two controllers. Everything is working now, I will try to reproduce in a smaller sample if I get the time.

Related

How does one access an Extension to a table in Acumatica Business Logic

Apologies if this question has been answered elsewhere, I have had trouble finding any resources on this.
The scenario is this. I have created a custom field in the Tax Preferences screen called Usrapikey.
This value holds an api key for a call that gets done in some custom business logic.
The custom business logic however occurs on the Taxes screen.
So within the event handler I need to access that API key value from the other screen. I have tried instantiating graphs and using linq and bql but to no avail.
below is what I have currently and my error is: No overload for method 'GetExtension' takes 1 arguments
If I am going about this the wrong way please let me know if there is a more civilized way to do this
protected virtual void _(Events.FieldUpdated<TaxRev, TaxRev.startDate> e)
{
var setup = PXGraph.CreateInstance<TXSetupMaint>();
var TXSetupEX = setup.GetExtension<PX.Objects.TX.TXSetupExt>(setup);
var rateObj = GetValues(e.Row.TaxID, TXSetupEX.Usrapikey);
decimal rate;
var tryRate = (Decimal.TryParse(rateObj.rate.combined_rate, out rate));
row.TaxRate = (decimal)rate * (decimal)100;
row.TaxBucketID = 1;
}
Many Thanks!
Well, acumatica support got back. It seems if you want to access the base page use:
TXSetup txsetup = PXSetup<TXSetup>.Select(Base);
To get the extension use:
TXSetupExt rowExt = PXCache<TXSetup>.GetExtension<TXSetupExt>(txsetup);
Then you can access the extension fields like so:
var foo = rowExt.Usrfield;

Conversion Of Map Location To String

Below is the code i am running with all other.. Its running perfectly adn its showing all the desired locations on map.
But what i want now is to store all the marked locations in such a way that i can show them as a list on a new page.
I am not able to retrieve the resulted location from map in the form of some string or may be something else which can be displayed as a list ...
private void Button_Click_3(object sender, RoutedEventArgs e)
{
MapsTask mapsTask = new MapsTask();
string search = "Coffee";
mapsTask.SearchTerm = search;
mapsTask.ZoomLevel = 2;
mapsTask.Show(); }
The MapsTask does not return any information.
If you're looking to get Points of Interest for a given location, you may have to use an external service such as the HERE Places API.

How can I read a string directly into a variable? Java, slick

I want to program some kind of game where the player has to name loacations shown on a map. I am using the slick library.
My problem is that I need some way to get the keyboard input from the player. I tried it with InputDialog from JOptionPane but I do not really like it. I would rather have the string appear on some part of the screen. But I do not have any idea how I can read from the keyboard directly into a variable that should be drawn on the screen. I thought that it would be possible to use streams but if I try to get some examples, they are always about reading from files and I do not know how to use that for reading from keyboard.
String answer;
public void render(GameContainer gameContainer, StateBasedGame sbGame, Graphics g){
g.drawString(answer, 50, 50);
}
public void update(GameContainer gameContainer, StateBasedGame sbGame, int delta){
//user types something which I now call "inputFromUser"
//it does not appear anywhere before the string is drawn on the screen.
answer = inputFromUser;
}
Something like a Scanner does not work for me because the user has to type that into the console, and I want him to type it "directly into the game" like it works with a textfield. (But I do not want to use a textfield.)
I have one way to accomplish that but it's fairly resource intensive. First create a global variable to keep track of the current letters. now create a new method that runs through all of the keys to check if they are down
private String totalString;
private void handelUserInput(Input input){
if(input.isKeyDown(Input.KEY_BACK)){
totalString = totalString.substring(0, totalString.length() - 1);
}
if(input.isKeyDown(Input.KEY_A)){
totalString += "a";
}
if(input.isKeyDown(Input.KEY_B)){
totalString += "b";
}
...etc
}
next create an input handler in the update loop to pass into the handle input method.
public void update(GameContainer gc, StateBasedGame sbg, int delta)throws SlickException {
Input input = gc.getInput();
handelUserInput(input);
}
and then print the string somewhere on your window in the render loop. by the way the Input class is built into slick.

get back to lower level j2me

I have a textfield (lower level) a call a function that call a higher level form that contains a datafield to pick up a date and display it in my textfield lowerlevel.
The problem is I cannot get back to my textfield (lower level) since the datefield appears
public void formdatepicker() {
final javax.microedition.lcdui.Command CONFIRM_COMMAND
= new javax.microedition.lcdui.Command("OK",
javax.microedition.lcdui.Command.OK, 1);
javax.microedition.lcdui.Command CANCEL_COMMAND
= new javax.microedition.lcdui.Command("Cancel",
javax.microedition.lcdui.Command.CANCEL, 2);
final DateField datefield = new DateField("Pick a date", DateField.DATE);
form.append(datefield);
form.addCommand(CONFIRM_COMMAND);
form.addCommand(CANCEL_COMMAND);
form.setCommandListener(new CommandListener() {
public void commandAction(javax.microedition.lcdui.Command c, Displayable d) {
if (c == CONFIRM_COMMAND) {
Date date = datefield.getDate();
display.setCurrent(null);// try to hide the current form to get
}
}
});
Display.getInstance().getJ2MEDisplay().setCurrent(form);
Your mistake is wrong assumption about what setCurrent(null) does. Per your question and code snippet, it looks like you expect it to somehow show the screen that has been displayed prior to form. It doesn't, see the exaplanation in the API javadocs (available online):
The application may pass null as the argument to setCurrent(). This does not have the effect of setting the current Displayable to null; instead, the current Displayable remains unchanged. However, the application management software may interpret this call as a request from the application that it is requesting to be placed into the background...
If you want to use setCurrent(Displayable) to show some screen instead of current one, you need to pass this screen as an argument to setCurrent.
For the sake of completeness, note that there is another version of setCurrent that accepts two parameters, first of which is Alert, which works a bit differently, but it is not applicable in your case because you use Form not Alert.

iOS 5 + GLKView: How to access pixel RGB data for colour-based vertex picking?

I've been converting my own personal OGLES 2.0 framework to take advantage of the functionality added by the new iOS 5 framework GLKit.
After pleasing results, I now wish to implement the colour-based picking mechanism described here. For this, you must access the back buffer to retrieve a touched pixel RGBA value, which is then used as a unique identifier for a vertex/primitive/display object. Of course, this requires temporary unique coloring of all vertices/primitives/display objects.
I have two questions, and I'd be very grateful for assistance with either:
I have access to a GLKViewController, GLKView, CAEAGLLayer (of the GLKView) and an EAGLContext. I also have access to all OGLES 2.0
buffer related commands. How do I combine these to identify the color
of a pixel in the EAGLContext I'm tapping on-screen?
Given that I'm using Vertex Buffer Objects to do my rendering, is there a neat way to override the colour provided to my vertex shader
which firstly doesn't involve modifying buffered vertex (colour)
attributes, and secondly doesn't involve the addition of an IF
statement into the vertex shader?
I assume the answer to (2) is "no", but for reasons of performance and non-arduous code revamping I thought it wise to check with someone more experienced.
Any suggestions would be gratefully received. Thank you for your time
UPDATE
Well I now know how to read pixel data from the active frame buffer using glReadPixels. So I guess I just have to do the special "unique colours" render to the back buffer, briefly switch to it and read pixels, then switch back. This will inevitably create a visual flicker, but I guess it's the easiest way; certainly quicker (and more sensible) than creating a CGImageContextRef from a screen snapshot and analyzing that way.
Still, any tips as regards the back buffer would be much appreciated.
Well, I've worked out exactly how to do this as concisely as possible. Below I explain how to achieve this and list all the code required :)
In order to allow touch interaction to select a pixel, first add a UITapGestureRecognizer to your GLKViewController subclass (assuming you want tap-to-select-pixel), with the following target method inside that class. You must make your GLKViewController subclass a UIGestureRecognizerDelegate:
#interface GLViewController : GLKViewController <GLKViewDelegate, UIGestureRecognizerDelegate>
After instantiating your gesture recognizer, add it to the view property (which in GLKViewController is actually a GLKView):
// Inside GLKViewController subclass init/awakeFromNib:
[[self view] addGestureRecognizer:[self tapRecognizer]];
[[self tapRecognizer] setDelegate:self];
Set the target action for your gesture recognizer; you can do this when creating it using a particular init... however I created mine using Storyboard (aka "the new Interface Builder in Xcode 4.2") and wired it up that way.
Anyway, here's my target action for the tap gesture recognizer:
-(IBAction)onTapGesture:(UIGestureRecognizer*)recognizer {
const CGPoint loc = [recognizer locationInView:[self view]];
[self pickAtX:loc.x Y:loc.y];
}
The pick method called in there is one I've defined inside my GLKViewController subclass:
-(void)pickAtX:(GLuint)x Y:(GLuint)y {
GLKView *glkView = (GLKView*)[self view];
UIImage *snapshot = [glkView snapshot];
[snapshot pickPixelAtX:x Y:y];
}
This takes advantage of a handy new method snapshot that Apple kindly included in GLKView to produce a UIImage from the underlying EAGLContext.
What's important to note is a comment in the snapshot API documentation, which states:
This method should be called whenever your application explicitly
needs the contents of the view; never attempt to directly read the
contents of the underlying framebuffer using OpenGL ES functions.
This gave me a clue as to why my earlier attempts to invoke glReadPixels in attempts to access pixel data generated an EXC_BAD_ACCESS, and the indicator that sent me down the right path instead.
You'll notice in my pickAtX:Y: method defined a moment ago I call a pickPixelAtX:Y: on the UIImage. This is a method I added to UIImage in a custom category:
#interface UIImage (NDBExtensions)
-(void)pickPixelAtX:(NSUInteger)x Y:(NSUInteger)y;
#end
Here is the implementation; it's the final code listing required. The code came from this question and has been amended according to the answer received there:
#implementation UIImage (NDBExtensions)
- (void)pickPixelAtX:(NSUInteger)x Y:(NSUInteger)y {
CGImageRef cgImage = [self CGImage];
size_t width = CGImageGetWidth(cgImage);
size_t height = CGImageGetHeight(cgImage);
if ((x < width) && (y < height))
{
CGDataProviderRef provider = CGImageGetDataProvider(cgImage);
CFDataRef bitmapData = CGDataProviderCopyData(provider);
const UInt8* data = CFDataGetBytePtr(bitmapData);
size_t offset = ((width * y) + x) * 4;
UInt8 b = data[offset+0];
UInt8 g = data[offset+1];
UInt8 r = data[offset+2];
UInt8 a = data[offset+3];
CFRelease(bitmapData);
NSLog(#"R:%i G:%i B:%i A:%i",r,g,b,a);
}
}
#end
I originally tried some related code found in an Apple API doc entitled: "Getting the pixel data from a CGImage context" which required 2 method definitions instead of this 1, but much more code is required and there is data of type void * for which I was unable to implement the correct interpretation.
That's it! Add this code to your project, then upon tapping a pixel it will output it in the form:
R:24 G:46 B:244 A:255
Of course, you should write some means of extracting those RGBA int values (which will be in the range 0 - 255) and using them however you want. One approach is to return a UIColor from the above method, instantiated like so:
UIColor *color = [UIColor colorWithRed:red/255.0f green:green/255.0f blue:blue/255.0f alpha:alpha/255.0f];

Resources