1 (edited by dizzymediainc 2018-02-28 03:36:20)

Topic: Multiple 3D Marker Lat/Long Set

Hello,

I am attempting to set the lat and long for each marker created though the code based on the variables saved. Currently it seems to work for the most part except I can only grab the first lat/long and not the 2nd, so when it creates the markers, it only grabs the first long/lat values and not the second pair (out of 2) from the float lists upon creating the new Vector2 values (what i see is the list count is returning 1 less than the actual list count when i go for (int i; i = 0, etc.))

The system is grabbing values from a user on a database based on user requests received, then saves the values to floats which then creates new Vector2 values in a list, in turn those Vector2 values are used to set the lat/long of the markers new Vector2 lat/long on marker creation.

I've tried various ways to get it all to work properly but haven't come to a good conclusion, i tried in the update function, separate functions or IEnumerators with small gaps in between list addition/variable grabs.

Any thoughts on how to get this to work would be great, thanks! (if not, perhaps a way of setting each markers long/lat after creation?)

Here's the code:

    [FoldoutGroup("Bools")]
    public bool markerPosLock;
    
    [FoldoutGroup("Bools")]
    public bool markerLock;

    [FoldoutGroup("Floats")]
    public List<float> latFloats;
    
    [FoldoutGroup("Floats")]
    public List<float> longFloats;

    [FoldoutGroup("Vector2")]
    public List<Vector2> markerPosition;

    [FoldoutGroup("Marker")]
    public List<OnlineMapsMarker3D> locationMarker;

    [FoldoutGroup("Marker")]
    public GameObject markerPrefab;


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///                                                                                                                                                                                                                   
///     Load user friend requests sent                                                                            
///                                                                                                                                                                                                         
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    public void UserFriendRequestsSentLoad() {

    if(!friendRequestsSentLoaded) {
    
        //contactError.text = "Loading...";
        CombuManager.localUser.LoadFriends(eContactType.PendingRequest, (bool success) => { 
             
    
            if (success) {
            
                Debug.Log(success);
                
                if (CombuManager.localUser.pendingRequests.Length == 0) {
                    
                    friendRequestsSentLoaded = true;

                    UserFriends();
                    Debug.Log("No Sent Friend Requests");
                
                } else {
                    
                    OnlineMapsControlBase3D control = OnlineMapsControlBase3D.instance;
  
                    locationMarker = new List<OnlineMapsMarker3D>();
                    
                
            for (int i = 0; i < CombuManager.localUser.pendingRequests.Length; ++i) {

                    User userReSe = (User)CombuManager.localUser.pendingRequests[i];

                    latFloats.Add(float.Parse(userReSe.customData["latitude"].ToString()));
                    longFloats.Add(float.Parse(userReSe.customData["longitude"].ToString()));
                    
                Debug.Log("Friend Requests Sent = " + CombuManager.localUser.pendingRequests[i].userName);
                     
                }
                    
                Debug.Log("Friend Requests Sent = " + CombuManager.localUser.pendingRequests.Length);
                    
                    
            for (int f = 0; f < longFloats.Count; ++f) {
                            
                for (int f2 = 0; f2 < latFloats.Count; ++f2) {
                        
                    if(!markerPosLock){
                        
                        foreach (var PendingRequests in CombuManager.localUser.pendingRequests){
                            
                            markerPosition.Add(new Vector2(longFloats[f], latFloats[f2]));
                            
                        }
                        
                        markerPosLock = true;
                    }
                }
            }                

                    
            
            for (int m = 0; m < markerPosition.Count; ++m) {
                        
                if(!markerLock){    
                    
                    foreach (var PendingRequests in CombuManager.localUser.pendingRequests){
                            
                            locationMarker.Add(control.AddMarker3D(markerPosition[m].x, markerPosition[m].y, markerPrefab));
                        
                        }
                    
                        markerLock = true;
                    }   
                }
                    
                    friendRequestsSentLoaded = true;
                    UserFriends();
                
               }
            
            } else {
            
                Debug.Log("Failed to load sent friend requests");
            }
        });
        
    //end friendRequestsGalLoaded    
    } else {
    
        Debug.Log("Friend Requests Already Loaded");
    }
}

Re: Multiple 3D Marker Lat/Long Set

Hello.

I see quite a lot of problems in your code:
1. As far as I understand, the anonymous method from LoadFriends should be called when updating the position of friends. But you only create new markers, and do not update existing ones.
2. Why do you need so many lists? This only makes sense for debugging purposes. But again, you just add the elements, and do not check the values in the lists.
3. In the second loop, where you create a list of items, you have errors in logic:
3.1. You add a lot of positions only from the values of longFloats[0] and latFloats[0].
3.2. Then you block the addition of positions using markerPosLock, and all next iterations do not work.
3.3. Even if you'll remove markerPosLock, this will work incorrectly, because you will first add a lot of the values of longFloats [0] and latFloats [0], then a lot of the values of {0, 1}, etc.
This is completely wrong.

Theoretically (because I can not test this), the correct way:

OnlineMapsControlBase3D control = OnlineMapsControlBase3D.instance;

if (locationMarkers == null) locationMarkers = new Dictionary<string, OnlineMapsMarker3D>();

for (int i = 0; i < CombuManager.localUser.pendingRequests.Length; ++i)
{
    User userReSe = (User)CombuManager.localUser.pendingRequests[i];

    float lat = float.Parse(userReSe.customData["latitude"].ToString());
    float lng = float.Parse(userReSe.customData["longitude"].ToString());

    OnlineMapsMarker3D marker;
    if (locationMarkers.TryGetValue(userReSe.markerID, out marker))
    {
        marker.SetPosition(lng, lat);
    }
    else
    {
        locationMarkers.Add(userReSe.markerID, control.AddMarker3D(lng, lat, markerPrefab));
    }

    Debug.Log("Friend Requests Sent = " + CombuManager.localUser.pendingRequests[i].userName);

}

Debug.Log("Friend Requests Sent = " + CombuManager.localUser.pendingRequests.Length);
Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

3 (edited by dizzymediainc 2018-02-28 17:12:20)

Re: Multiple 3D Marker Lat/Long Set

1. As far as I understand, the anonymous method from LoadFriends should be called when updating the position of friends. But you only create new markers, and do not update existing ones.


Actually I have to call LoadFriends to get the pending friend requests data (being customData) BEFORE updating the positions or else, setting the marker position won't work properly unless it's set to 0,0 and then adjusted after marker creation, I found no good way to do this.


3. In the second loop, where you create a list of items, you have errors in logic:
3.1. You add a lot of positions only from the values of longFloats[0] and latFloats[0].
3.2. Then you block the addition of positions using markerPosLock, and all next iterations do not work.


3.1 The entire post is based around this section, it returns values from item 0 in the list and not both 0 and 1
3.2 If I don't block the position creation, it duplicates and creates 8 instead of 2, currently it creates 2 (which is what I want) but sets the values for both from the item 0 in the long/lat list.


3.3. Even if you'll remove markerPosLock, this will work incorrectly, because you will first add a lot of the values of longFloats [0] and latFloats [0], then a lot of the values of {0, 1}, etc.

Actually i've thoroughly tested this and it does work somewhat if I remove the markerPosLock, being that it creates 8 instead of 2 values, for some reason when it creates 8 values the long/lat values are set properly (so out of 8 it goes : 0,1,0,1,0,1,0,1)


SUGGESTED CODE:

I haven't tested this yet, will test it in a bit but looking it over I am confused at to what markerID is and where it came from or what to reference it to. Thoughts?

Also why is lat/long floats singular? I need a list of the values being that there will probably be more than one user friend request.


EDITS:

Being that this is one of the critical parts of the code (as it generates the proper amount based on friend requests):

foreach (var PendingRequests in CombuManager.localUser.pendingRequests){ }

What was the reason you decided to remove it in the suggested code?

Re: Multiple 3D Marker Lat/Long Set

Actually I have to call LoadFriends to get the pending friend requests data (being customData) BEFORE updating the positions or else, setting the marker position won't work properly unless it's set to 0,0 and then adjusted after marker creation, I found no good way to do this.

It does not matter when to set the position.

If I don't block the position creation, it duplicates and creates 8 instead of 2, currently it creates 2 (which is what I want) but sets the values for both from the item 0 in the long/lat list.

It is important not only the number of values, but also the values that you use.
This creates 8 values, because longFloats contains 2 values, latFloats contains 2 values, and pendingRequests also contains 2 values.
2 * 2 * 2 = 8.

Also, keep in mind that when you get the next response, you will have 40 markers, instead of the expected 4 markers.
4 * 4 * 2 + 8 = 40

I haven't tested this yet, will test it in a bit but looking it over I am confused at to what markerID is and where it came from or what to reference it to. Thoughts?

You plan to only create markers, or update their position in the future.
If you plan to update the positions, how do you know which marker to update?
To do this, use some ID.
I do not know how this field is called in your class.
But in the correct structure of the application you are determined to have something like that.

Also why is lat/long floats singular?

These are absolutely useless lists.
This makes some sense only for debugging purposes.
But in fact, there are better ways to debug the application.

What was the reason you decided to remove it in the suggested code?

Look closely at the code.
It still uses CombuManager.localUser.pendingRequests.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

5 (edited by dizzymediainc 2018-02-28 20:28:34)

Re: Multiple 3D Marker Lat/Long Set

Alex Vertax wrote:

It does not matter when to set the position.

No, it matters when and where i grab the info from the pending friend requests

This creates 8 values, because longFloats contains 2 values, latFloats contains 2 values, and pendingRequests also contains 2 values. 2 * 2 * 2 = 8

Yea I kind of figured that, that's why i added the manual lock.

You plan to only create markers, or update their position in the future.
If you plan to update the positions, how do you know which marker to update?
To do this, use some ID.

Sure that makes sense although as i asked, what is it referencing to? As i see in your example code it doesn't show, so how would i create the base for this value and what is it assigned to? (float, int, string, etc.)

These are absolutely useless lists.

Ok but that doesn't answer my question, is the way you have it actually grabbing the multiple values from the multiple users? As far as i see, it's singular and only grabbing one, therefore it would only assign that one set of floats to both users.

Look closely at the code.

I did and you completely removed

foreach (var PendingRequests in CombuManager.localUser.pendingRequests){

}


This is there specifically to generate the proper amount of makers based on the amount of pending requests, so without it, it's merely generating one unless the example code you provided is somehow, finding out how many users are in pending requests and then instantiating them based on that value.

Re: Multiple 3D Marker Lat/Long Set

Yea I kind of figured that, that's why i added the manual lock.

It does not work that way.
Of course it's not my business at all how you write your application.
But you showed me this code, and I see that this will not work.
I explained to you why this will not work, and showed the correct (theoretically) way.

Sure that makes sense although as i asked, what is it referencing to? As i see in your example code it doesn't show, so how would i create the base for this value and what is it assigned to? (float, int, string, etc.)

This is just some variable that stores the user ID.
The type of this variable depends on how you store it in your database.
Usually this is an int or string.

Ok but that doesn't answer my question, is the way you have it actually grabbing the multiple values from the multiple users? As far as i see, it's singular and only grabbing one, therefore it would only assign that one set of floats to both users.

I do not even know how to answer this.
Read something about local variables.
Or just add Debug.Log and check what these variables contain.

I did and you completely removed
foreach (var PendingRequests in CombuManager.localUser.pendingRequests)

for (int i = 0; i < CombuManager.localUser.pendingRequests.Length; ++i)
{
    User userReSe = (User)CombuManager.localUser.pendingRequests[i];

This is the same in 98% of the cases.
There are two cases where this is wrong:
1. If pendingRequests only implements IEnumerable.
2. If pendingRequests has some kind of very-very special indexer. I've never seen this, but theoretically it's possible.
You already use it in such a way in the first loop, so this is not one of these two cases.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Multiple 3D Marker Lat/Long Set

Alright well after some more tinkering i got it working:

                    OnlineMapsControlBase3D control = OnlineMapsControlBase3D.instance;

                if (locationMarker == null) locationMarker = new Dictionary<string, OnlineMapsMarker3D>();

                    for (int i = 0; i < CombuManager.localUser.pendingRequests.Length; ++i) {
                        
                        User userReSe = (User)CombuManager.localUser.pendingRequests[i];
                        
                        string markerID = userReSe.id;

                        float lat = float.Parse(userReSe.customData["latitude"].ToString());
                        float lng = float.Parse(userReSe.customData["longitude"].ToString());

                        OnlineMapsMarker3D marker;
    
                    if (locationMarker.TryGetValue(markerID, out marker)) {
                        
                        marker.SetPosition(lng, lat);
                        
                    } else {
                        
                        locationMarker.Add(markerID, control.AddMarker3D(lng, lat, markerPrefab));
                        
            }

                Debug.Log("Friend Requests Sent = " + CombuManager.localUser.pendingRequests[i].userName);

            }

Currently my issue is accessing the specific info based on the key name, in this instance i'm using the id number of the user account, I tried the username but found that I was unable to access the ID number afterwords.

In this case the ID numbers are 25 and 33 but it seems to only return 25, I can load the profile pic but i'd like to load the info based on the marker clicked on, which should coincide with the key name. Currently I grab the username, profile pic, etc. but only of ID 25.


    public void LoadMapProfPic(){
        
        OnlineMapsMarker3D marker;
        
        FilePathUrlInfo fileInfo = currentImage.GetComponent<FilePathUrlInfo>();
        
            //if pending requests is 0
            if(CombuManager.localUser.pendingRequests.Length == 0){
             
                Debug.Log("NO pendingRequests");
                
            } else {
                
               //update request sent int based on pending requests length
                CombuDemo.instance.requestSentGalInt = CombuManager.localUser.pendingRequests.Length;
                
                if the request sent list is empty, create a new list
                if(CombuDemo.instance.requestsSentList.Count == 0){
                    
                    //mapFileList = new List<UserFile>();
                    CombuDemo.instance.requestsSentList = new List<UserFile> ();
                }
                
                
                
            for (int i = 0; i < CombuManager.localUser.pendingRequests.Length; ++i) {
                
                User userReSe = (User)CombuManager.localUser.pendingRequests[i];
                
                string markerID = userReSe.id;
                
                string actImage = "" + userReSe.customData["ActiveImage"];
                
                if(!locked){
                


                    foreach(var key in MapMarkerHandler.instance.locationMarker){
                        
                        if (key.Key.Equals(markerID)){

                           //set username text
                            currentMapHandler.GetComponent<MapMakerHandler>().userNameText.text = key.Key;
                            
                            //load files based on key name
                            UserFile.Load (key.Key, false, 1, 6, (UserFile [] files, int recordCount, int pageCount, string error) => {
        
                                foreach (var file in files) {
        
                                    if (file.name == actImage) {
                                        
                                        if(CombuDemo.instance.requestsSentList.Count == 0){
                                        
                                            //add to request sent list
                                            CombuDemo.instance.requestsSentList.Add(file);
                                            Debug.Log("key.Key added to requestSentList");
                                        
                                            //load profile image
                                            fileInfo.LoadFilePathUrl(file);
                                            Debug.Log("load key.Key file");
                                            
                                        } else {
                                            
                                       //on re-check if file does not equal one that is already present, load a new file
                                        for (int r = 0; r < CombuDemo.instance.requestsSentList.Count; ++r) {
                                            
                                            if(file.name != CombuDemo.instance.requestsSentList[r].name){
                                        
                                                CombuDemo.instance.requestsSentList.Add(file);
                                                Debug.Log("key.Key new added to requestSentList");
                                        
                                                fileInfo.LoadFilePathUrl(file);
                                                Debug.Log("load key.Key new file");
                                            }
                                                
                                        }
                                        }
                                        
                                    }
                                }
                            });

                            }
                        
                        }
                    
                
                locked = true;
                    
                }
            }
                
        }
    }

i've considered doing it the same way as you suggested for the marker set setup but am unsure what to replace for the marker set or create fields in order to get my desired effect.

                    if (locationMarker.TryGetValue(markerID, out marker)) {
                        
                        marker.SetPosition(lng, lat);
                        
                    } else {
                        
                        locationMarker.Add(markerID, control.AddMarker3D(lng, lat, markerPrefab));
                        
            }

Any thoughts on this would be helpful, thanks!

Re: Multiple 3D Marker Lat/Long Set

You only get 25 because you use "locked".
After the first iteration your code is blocked.

Also, why do you need to check the ID of each marker in the second script, if you can just use TryGetValue?!

foreach(var key in MapMarkerHandler.instance.locationMarker)

Maybe I'm wrong, but you do not use key.Value.
You already have the key (markerID), so this loop does not make sense.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Multiple 3D Marker Lat/Long Set

Like I said any suggestions would be great, acting like I understand every aspect of your system is not that helpful heh

As I am new to your system and still learning how it works, plus combining it with another system, i'll be going about things in various ways to make both work together.

So any suggestions in the right direction is definitely more ideal than telling me it doesn't make sense tongue

Yes as I mentioned I considered using TryGetValue but was unsure how to utilize it in my current situation, again, direction in the proper way to utilize this function would be ideal.

Thanks.

Re: Multiple 3D Marker Lat/Long Set

Please read the first two lines of my previous post.
I directly pointed out to you why your script works only for the first ID.

In your scripts, only two methods are related to the map: AddMarker3D and SetPosition.
Do you have problems with these methods?! No, because you are asking about something else.

Everything else is just your scripts in which you are trying to implement the required behavior.
But it has no relation to the map.

It's not hard for me to look at your code and say what's wrong. And I did it.
In addition, I showed you the problems in your code that you did not ask about, just because I see them.
But I really do not understand what you want / expect more.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Multiple 3D Marker Lat/Long Set

I lock it on purpose as if I don't, it grabs all the ID's and only displays the very last one, so that would be obvious if tested.

Sorry but you didn't answer my question and your response in short, is very rude and not helpful in any way.

What I expect is courteous customer support for a product you have for sale, this is common sense and as with any company or individual that provides customer service, patience and actual willingness to help solve the issue, is ideal.

Unfortunately I have met way too many asset developers who act the way you have been, which is that I should know how your system works right off the bat and if I don't and i'm doing something in a way you wouldn't, i'm stupid? lol that's how you present yourself and like i said, it's rude.

Thanks for your time anyways, even if it didn't assist in any way.

Re: Multiple 3D Marker Lat/Long Set

I'm sorry if my answer seemed rude to you.
I never even tried to rude to you or anyone else.
I never wrote that you or someone else is stupid.

Perhaps the problem is that you did not correctly formulate your question (in fact, your post 7 did not contain the question at all).
What I see in the 7th post:
- Two pieces of code.
The first is most likely called when the server responds.
When called the second is absolutely not clear.
- A short description about problems with ID.
- Suggestion to implement something like in the third piece of code.
And this suggestion confuses me.
Really. This generates a million questions, for example:
1. Why this should be there?
2. Why do you need to create markers when loading profile pic?
3. Where should this be, because you do not create markers in the second script?

I've been developing assets and providing support for many years, and have almost telepathic abilities by reading the description the problem.
Unfortunately, in your case this does not work.

Let's try to start from the beginning.
You explain in detail what and why you want to do.
I explain to you how to do this.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Multiple 3D Marker Lat/Long Set

It's alright I ended up finding a solution to my issue, i simply assigned the captured values manually to the marker prefab before instantiation/adding to control, so this way i get the specific info for each marker created. So dummy 1 values (active image, id, etc.) and dummy 2 values (active image, id, etc.) set properly on the custom script.

Afterwards I clear the set values when the scene resets/stops/etc.

                    
                    OnlineMapsControlBase3D control = OnlineMapsControlBase3D.instance;

                if (locationMarker == null) locationMarker = new Dictionary<string, OnlineMapsMarker3D>();

                    for (int i = 0; i < CombuManager.localUser.pendingRequests.Length; ++i) {
                        
                        User userReSe = (User)CombuManager.localUser.pendingRequests[i];
                        
                        string markerID = userReSe.userName;
                        
                        string userID = userReSe.id;
                        
                        string actImg = userReSe.customData["ActiveImage"].ToString();

                        float lat = float.Parse(userReSe.customData["latitude"].ToString());
                        float lng = float.Parse(userReSe.customData["longitude"].ToString());

                        OnlineMapsMarker3D marker;
    
                    if (locationMarker.TryGetValue(markerID, out marker)) {
                        
                        marker.SetPosition(lng, lat);
                        
                    } else {
                        
                        markerPrefab.GetComponent<MapMakerHandler>().userName = markerID;
                        markerPrefab.GetComponent<MapMakerHandler>().userID = userID;
                        markerPrefab.GetComponent<MapMakerHandler>().activeImage = actImg;
                        
                        locationMarker.Add(markerID, control.AddMarker3D(lng, lat, markerPrefab));
                        
            }

                Debug.Log("Friend Requests Sent = " + CombuManager.localUser.pendingRequests[i].userName);

            }

            Debug.Log("Friend Requests Sent = " + CombuManager.localUser.pendingRequests.Length);


    //resets custom markerPrefab values after scene ends/resets
    void OnDestroy() {
     
        markerPrefab.GetComponent<MapMakerHandler>().userID = "";
        markerPrefab.GetComponent<MapMakerHandler>().userName = "";
        markerPrefab.GetComponent<MapMakerHandler>().activeImage = "";
        
    }