Is it not possible to get altitude from MKUserLocation in IOS MKMapKit? - mkmapview

Is it possible to get altitude from MKUserLocation in IOS MKMapKit?
Specifically I'm trying to get altitude within the MKMapViewDelegate's callback "didUpdateUserLocation" which provides an MKUserLocation object?
If not should I really be using CLLocationManager with it's startUpdatingLocation() method to capture location & altitude changes and scrap the use of mapview's MKMapViewDelegate's callback "didUpdateUserLocation"???

missed it:
MKUserLocation.location.altitude property

Related

How to invoke a function when changing position?

I'm trying to invoke a function everytime the position of a position2D node is changed
I tried to override the setter as given in the docs like this:
extends Position2D
tool
func set_position(value):
print("changed position ",value)
self.position=value;
what am I missing here? is there a way to achieve what I'm trying?
The method set_position is not virtual. You are not overriding it. At best you are hiding it.
If you want to follow that approach, intercept the property instead, using _set (Notice that the documentation mentions that _set is virtual). The idea is that we are going to take the attempt to set position, do whatever we want to do when it is set, and then let it continue normally.
func _set(property:String, value) -> bool:
if property == "position":
print("changed position ",value)
return false
And you should see that when you modify the position in the inspector panel, you get the message.
I suspect that is not enough for you. In particular the above solution does not detect when the position changes because you drag the Position2D in the editor.
This is becase when you move the Position2D in the editor, Godot is not setting the position property. Instead it is (after digging in the source code) calling the undocumented method _edit_set_position… Which you can also call from GDScript! Anyway, the point is we cannot intercept it (and we cannot override it. Yes, I tried).
Instead we are going to use _notification. We are looking for NOTIFICATION_TRANSFORM_CHANGED, but to get that notification we need to enable it with set_notify_transform. The code looks like this:
tool
extends Position2D
func _enter_tree() -> void:
set_notify_transform(true)
func _notification(what: int) -> void:
if what == NOTIFICATION_TRANSFORM_CHANGED:
print("changed position", position)
With this approach you will also be able to react to when the user moves the Position2D in the editor by dragging it around or with the keyboard directional keys. Which are the cases where Godot uses _edit_set_position. Or any other means that we could not intercept with the initial approach.
You can use this approach if you need to do something every time the Node2D moves, but it does not move very often.
By the way, this also works for 3D.

Mapbox SDK - App crashes when using animateCamera during click event

I'm working with Mapbox SDK for Android and I'm doing a simple task of "click and move" but for some reason whenever I click on a location and the camera moves to the location, the app crashes with the following error.
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.mapbox.mapboxsdk.maps.MapboxMap.animateCamera(com.mapbox.mapboxsdk.camera.CameraUpdate, int)' on a null object reference
The error then points to this line.
mapboxMap.animateCamera(CameraUpdateFactory
in
mapboxMap.animateCamera(CameraUpdateFactory
.newCameraPosition(new CameraPosition.Builder()
.target(new LatLng(latLng))
.zoom(13)
.build()), 1500);
The LatLng is not empty. I made sure to validate if the coordinates are being passed and they are.
As a matter of fact, even if I hardcode the coordinates (lat / lng) it still crashes.
Note: This happens with moveCamera(), easeCamera() and animateCamera().
'void com.mapbox.mapboxsdk.maps.MapboxMap.moveCamera(com.mapbox.mapboxsdk.camera.CameraUpdate)' on a null object reference
'void com.mapbox.mapboxsdk.maps.MapboxMap.easeCamera(com.mapbox.mapboxsdk.camera.CameraUpdate)' on a null object reference
However, one thing to note is that if I place that code in the onMapReady() instance, the map loads with the camera positioned where the coordinates point to but if I perform a click event to trigger the function to move the camera to where I clicked, it crashes.
Another thing I'd like to mention is that when I click the camera actually GOES to the location but it crashes right away. The reason I know this is because when the android studio emulator tries to "recover the app", it shows the map on the location it was meant to go to.
Any ideas why this happens?
other functions like forward and reverse geocoding work just fine when I perform a click event.
The problem I was having which was making the function not recognize the map itself and thus returning NULL was:
#Override
public void onMapReady(#NonNull final MapboxMap mapboxMap) {
mapboxMap = mapboxMap; //<=== THIS HERE WAS THE PROBLEM.
//It should be this.mapboxMap = mapboxMap
..........
I have the mapboxMap declare as a global in the activity but when the map initialized, it was assigning itself to the global variable and keeping it within the scope of the onMapReady and it was impossible for the function that moves the camera to locate the it all.
in any case, it all works now.

Object Collision Issue - Weird Behaviour - Unity

I wondering if someone could give me a hand with this problem I'm having with objects and collisions in Unity.
I have a sphere object being controlled by the users phone's accelerometer. The sphere moves around fine but once it hits a wall the sphere starts acting weird. It pulls in the direction of the wall it collided with, starts bouncing, and just overall not responsive anymore to the movement of the phone.
Any idea as to why this could be happening?
Here is the script used to control the player's sphere.
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float speed;
void Update() {
Vector3 dir = Vector3.zero;
dir.x = Input.acceleration.x;
dir.z = Input.acceleration.y;
if (dir.sqrMagnitude > 1)
dir.Normalize();
dir *= Time.deltaTime;
transform.Translate(dir * speed);
}
void OnTriggerEnter (Collider other)
{
if (other.gameObject.tag == "Pickup") {
other.gameObject.SetActive(false);
}
}
}
That happens because your object has a 'Rigidbody' component, and, I suppose, it's not a kinetic rigidbody. Basically, it behaves just like it should: a real physical object will not pass through another object, that is the most basic behaviour of a physics engine. However, since you don't operate with the physics-based object using forces, but manually change it's position, you break a level of abstraction. In result, you move the object inside the wall, and now it can't get out.
Use ApplyForce method instead. If you want to pull or push object (instead of just move, which contradicts the fact that these objects are managed by physics) in a certain direction every frame, you should use ForceMode.Acceleration (or ForceMode.Force, if you want the effect to depend on the mass) every physics frame, which means that you have to use FixedUpdate method instead of Update.

Incorrect conversion value for CGSize/SizeF binding

I'm working on MonoTouch binding project to integrate GMGridView into my application. I was able to successfully load the empty Grid view but was not able to load grid items. After spending hours on MonoTouch & Objective C code, it turned out that System.Drawing.SizeF binding is incorrectly translating to CGSize (i.e, SizeF(140f, 110f) is translating to CGSize(140, 0) - value of height is lost).
Objective C Definition
- (CGSize)GMGridView:(GMGridView *)gridView sizeForItemsInInterfaceOrientation:(UIInterfaceOrientation)orientation;
Monotouch Binding
[Abstract, Export ("GMGridView:sizeForItemsInInterfaceOrientation:")]
System.Drawing.SizeF SizeForItemsInInterfaceOrientation (GMGridView gridView, UIInterfaceOrientation orientation);
I was wondering if I'm binding it incorrectly or this is a known bug? Also, what would be a resolution other than creating additional callback for height value.
Binding and test code is posted here: GMGridMono
Thanks for looking into this.
I have encountered the same issue with bindings to a method returning CGSize. Monotouch V5.2.12. It happens on the simulator but not on the device. A direct call from a mono application to the method works fine, but when the method is used as a callback from the bound library to the mono code the returned Height value is incorrect and appears ininitialized.

How do I handle float in Core Data / iPhone?

I recently got started on Core Data, thanks to this tutorial :
http://www.techotopia.com/index.php/An_iPhone_OS_Core_Data_Tutorial
My question is about handling types other than String.
For example let us say I want to add to the existing fields (name,address and phone : which are all String(s) in the example presented), the weight which I want to be a float in my entity.
How would I change the code to handle a float instead of a String ?
I already tried to change one of the fields to float in my entity. First letting the code as it is, and the program crashed. Then I tried to adjust the code in some ways but it did not work. I have the feeling it must be simple, but I can't get it right.
Thanks for any tip.
you should use NSNumber for float (and access it with [myNumber floatValue]).
You can't use primitive values in CoreData entities - only objects. ( NSString, NSDate, NSNumber, NSData ... )
Hope this helps.

Resources