Google Maps Android API v2 getVisibleRegion() returns 0 - android-maps-v2

I am using the new Google Maps Android API v2 and need to detect latlng coordinates for the corners of my screen view. I use mMap.getProjection().getVisibleRegion() to do this, which works fine the first time I load the program, but if I leave the program and then re-open it (either via the back button or the home button) getVisibleRegion() returns latlng coordinates that are all (0.0, 0.0). I have a workaround where I save the VisibleRegion object as a global in the application class when I first open the program, but this seems like a bad idea. Anyone understand why the latlng coordinates go to zero (but not null) when re-opening? Thanks!
Edit: sometimes initial load gives a (0.0, 0.0) Visible Region so my workaround is not viable. Using getProjection().fromScreenLocation(point) also returns 0.

Okay, I think I solved it: I was guessing right: The map was not visible and therefore there is also no visibleRegion (in other words a region from 0,0,0,0 to 0,0,0,0). Similar to this question
Android Google Maps API v2 calling getProjection from onResume
I attached an onCameraChanged-Listener to my map. Everytime the map is moved (or the camera is available => There is a visibleRegion) this method is called.
private void initMap() {
mMap = getMap();
if (mMap != null) {
try {
mMap.setLocationSource(this);
mMap.setOnMarkerClickListener(this);
mMap.setOnCameraChangeListener(new OnCameraChangedListener() {
#Override
public void onCameraChange(CameraPosition cameraPosition) {
Log.d(TAG, "onCameraChange");
updateMapItems();
}
}
MapsInitializer.initialize(getActivity());
...
}
}
}
This listener makes sure that you have a visibleRegion.
UPDATE: Since the new update of the Google Maps API v2, there is a callback onMapReady(). I did not use it yet, but it seems to serve exactly the purpose of this question: https://developer.android.com/reference/com/google/android/gms/maps/OnMapReadyCallback.html

Related

UE5 Soft Object Pointer not working as argument

I’m trying to convert my Clue Management System in C++ and have made a Primary Data Asset to easily change the clue data. To make it as efficient and memory optimal as I can, I've decided to use soft object pointers to Data Assets that are loaded in as the clues are collected.
I'm trying to convert my Clue Management System in C++ and have made a Primary Data Asset to easily change the clue data. In my Clue Item code I have an interface call for attempting to interact with the Clue:
bool AClueBase::AttemptInteraction_Implementation(UInteractComponent* Interactor)
{
UE_LOG(LogClue, Display, TEXT("Clue Interacting"));
UClueManagerSubsystem* ClueManager = GetGameInstance()->GetSubsystem<UClueManagerSubsystem>();
if(!ClueManager) return false;
UE_LOG(LogClue, Display, TEXT("Clue Manager Valid"));
return ClueManager->CollectClue(ClueDataAsset);
}
This works fine, with the Clue Data Asset being a UPROPERTY:
UPROPERTY(BlueprintReadOnly, EditInstanceOnly) TSoftObjectPtr<UPrimaryDataAsset_Clue> ClueDataAsset;
The Function it is trying to call on the Clue Manager Subsystem is:
bool UClueManagerSubsystem::CollectClue(TSoftObjectPtr<UPrimaryDataAsset_Clue> Clue)
{
if(!Clue) return false;
UE_LOG(LogClue, Display, TEXT("Collecting Clue: %s"), *Clue->GetClueName());
FAreaClues AreaClues;
// If the Map has the Enum already, then we need to save a reference to the current value
if(CollectedClues.Contains(Clue->GetClueLocation()))
{
// If the Map has the Enum already, then we need to save a reference to the current value
AreaClues = CollectedClues[Clue->GetClueLocation()];
UE_LOG(LogClue, Display, TEXT("Clue Location already in Map"));
}
if(AreaClues.CollectedClues.Contains(Clue)) return false;
UE_LOG(LogClue, Display, TEXT("Clue doesn't already exist in Map"), *Clue->GetClueName());
AreaClues.CollectedClues.Add(Clue, true);
CollectedClues.Add(Clue->GetClueLocation(), AreaClues);
UE_LOG(LogClue, Display, TEXT("Clue Successfully Added"), *Clue->GetClueName());
OnCollectedClue.Broadcast(Clue);
return true;
}
It doesn't get past the first guard clause in this function, so the soft object pointer is a nullptr apparently. I am new to C++ with Soft Object Pointers so I might be entirely misusing them, so any correction would be greatly appreciated :)

Detecting orientation of iPhone using C++

Embarcadero C++Builder 10.3.2 Enterprise
Searching the internet, I could not find any FMX code for this. Based on Delphi code, this should have worked but the compiler does not like it
if (Application->FormFactor->Orientations == Fmx::Types::TScreenOrientations::Landscape) {
//Landscape
}
Also, the value of Application->FormFactor->Orientations is the same whatever the orientation of the iphone. {System::SetBase = {Data = {[0] = 11 '\v'}}}
How does one determine the orientation?
The Orientations property is a TFormOrientations, which is a System::Set of TFormOrientation values. You can't use Set::operator== to compare it to a single value, which is why you are getting a compiler error. However, you can use the Set::Contains() method to check if it has a given value, eg:
if (Application->FormFactor->Orientations.Contains(Fmx::Forms::TFormOrientation::Landscape)) {
//...
}
In any case, the Orientations property specifies which orientation(s) the application's Forms are allowed to take (a value of 11 has its 1st, 2nd, and 4th bits set to 1, which correspond to the Portrait, Landscape, and InvertedLandscape orientations being enabled). It does not report what the device's current orientation is. For that, use the IFMXScreenService::GetScreenOrientation() method instead, eg:
_di_IFMXScreenService ScreenService;
if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXScreenService), &ScreenService)) {
if (ScreenService->GetScreenOrientation() == Fmx::Types::TScreenOrientation::Landscape) {
//...
}
}

-Holographic Displays API- How to remove holograms near a player

I am making a plugin. That when a command is typed. It removes the nearest Holograms to the sender/player. Now, the things I have tried are to remove the Invisible armor stands in a radius of 10 blocks. I also tried to see if there is a method to get the nearest holograms, but I had no luck. If there is any way to point to what I need to do, that would be helpful. I am not asking for code, just for what I need to look under, say a specific class etc.
Thanks, seb.
Trying to remove armor stands:
for(Entity en : player.getNearbyEntities(10, 10, 10)) {
if(en instanceof ArmorStand) {
en.remove();
}
}
My Question: Where should I look to find a way to remove nearby Holograms to the player? If you can provide code, not needed though.
//Loop through all existing holograms registered to your plugin
for (Hologram hologram : HologramsAPI.getHolograms(plugin)) {
Location playerLoc = player.getLocation();
Location hologramLoc = hologram.getLocation();
//Check if the distance between the locations are less than 10
//and deletes the hologram if true
if (playerLoc.distance(hologramLoc) < 10) {
hologram.delete();
}
}
This Holographic Displays API has a hologram delete method.
https://github.com/filoghost/HolographicDisplays/wiki

Adding to a list from another class

I am trying to add the instance of an object that I click on to a list on my control object. However when I do so it says that the reference is not set to an instance of an object. The code I have to instantiate the list on the control object is:
public List<Transform> selected = new List<Transform>();
And I tried to add to it to that list using this code attached to the unit:
if (!selected)
{
// Set selected state
selected = true;
// Add to Selected List
control.GetComponent<ForwardCommandScript>().selected.Add(this.transform);
// Set material colour brighter
oldColour = gameObject.renderer.material.color;
newColour = oldColour + new Color(0.2f, 0.2f, 0.2f);
gameObject.renderer.material.color = newColour;
}
I have tried with transform as well. Later I will try to remove it by finding a reference id that was set when the unit is instantiated so should I try to add the script instead of the object if I need to find its variables and then delete the game object attached to the script. I have tried with the GameObject, transform and the class. I wanted to use the class so I can easily access the variables. I have posted this on unity answers and forums but no one replied in the week it was up and I don't like reposting the same stuff on the same site.
Cheers, Scobbo
Your error NullReferenceException: Object reference not set to an instance of an object states that something in the associated line is null. Since the error message doesn't state which part is null, you have to split your code up and check which part is failing.
I'm not sure how you split it up, but try it this way:
var script = control.GetComponent<ForwardCommandScript>();
if (script == null) Debug.Log("script not found");
if (script.selected == null) Debug.Log("selected is null");
script.selected.Add(this.transform);
Now you should get one of the two messages in your debug log before the exception raises. Either the script was not found and you have to check if it is correctly assigned to the game object and if control is the correct game object, or selected is null which should not happen if you initialized it like you posted...
Thanks for adding the complete Error Message :)
you need to replace
control.GetComponent<ForwardCommandScript>().selected.Add(this.transform);
with
control.GetComponent<ForwardCommandScript>().selected.Add(transform);
because
this
is a reference to the script and not the GameObject. you could also use gameObject.transform which transform is just an abbreviation for

getElementsByTagName returns 0-length list when called from didFinishLoad delegate

I'm using the Chromium port of WebKit on Windows and I'm trying to retrieve a list of all of the images in my document. I figured the best way to do this was to implement WebKit::WebFrameClient::didFinishLoading like so:
WebNodeList list = document->getElementsByTagName(L"img");
for (size_t i = 0; i < list.length(); ++i) {
// Manipulate images here...
}
However, when this delegate fires, list.length() returns 0. The only times I've seen it return a list of non-zero length is when I substitute "body" or "head" for "img". Strangely enough, if I call getElementsByTagName(L"img") outside of the delegate, it works correctly.
I'm guessing that the DOM isn't fully loaded when didFinishLoading is called, but that would seem to contradict the delegate's name. Does anyone know what I may be missing here?
It turns out that the mistake was purely on my side. I was caching a pointer to the DOM document in my frame wrapper. Of course, since a frame can outlive a DOM document, I ended up referencing an out-of-date document once I loaded a new page.