The radius is not working..?

Topics: Developer Forum, User Forum
Apr 8, 2011 at 6:47 PM
Edited Apr 8, 2011 at 10:47 PM

When I try to apply a radius setting to my search, it just returns 250 pictures from all over the world. I read that you need to set a min_date_taken or some other limitations, like a tag. I've tried all this, but still it just returns 250 pictures from all over. Can someone confirm that the radius option is actually working?

My codesnippet looks something like this:

 

 //Get dummy gps coordinates            
            latitude = 61.600447; //44.434944;//61.769509;// 10.737187; //500; ////61.454904;
            longitude = 5.035064; //4.88342; //106.75861; //500;// //5.82801;

            App app = Application.Current as App;
            //Set some options, long lat and pictures not older than 3 years from now
            PhotoSearchOptions options = new PhotoSearchOptions();
            options.Latitude = latitude;
            options.Longitude = longitude;
            options.MinTakenDate = DateTime.Now.AddYears(-3);
            options.Extras = PhotoSearchExtras.DateTaken | PhotoSearchExtras.Description | PhotoSearchExtras.LargeUrl | PhotoSearchExtras.MediumUrl
                | PhotoSearchExtras.OwnerName | PhotoSearchExtras.Geo;
            options.HasGeo = true;
            /*
            options.RadiusUnits = RadiusUnit.Kilometers;
            options.Radius = (float)radius; //also tried with 0.1 and many other values..        
            options.Tags = "2011";
            */
            //run the search..
If i run it like this, without the Radius settings, it returns the ones i want. But i also want to make it possible to increase the radius on the search...And I'm wondering why this does not work..
Anybody? :)
Coordinator
Apr 9, 2011 at 1:15 PM

Using a radius of 1 and the above settings I got 5 photos returned.

Make sure you're not checking the "PerPage" property as the default page size is 250. Check either the Count (to see how many photos in the current page) or Total (to see how many total photos are available on Flickr).

Sam

Apr 9, 2011 at 5:08 PM

Thanks Sam! Actually, when you said it worked with 1, I also tried. It worked. So, I set the code to: options.Radius = (int)radius; I changed the casting from (float) to (int), and then it seems to work fine. But isn't the Radius expecting a float number? It doesn't seem to work when i try to use it with floats?

 

Anyway, thanks! :)

Coordinator
Apr 10, 2011 at 3:07 PM

I used floats, such as 1.0f, 2.5f and 4.75f and they all returned values in increasing numbers as the radius got bigger.

What is your "radius" variable declared as and where is it set?

Apr 11, 2011 at 11:24 AM

It works if i set the radius programmatically to a floating number, like 1.0f, 2.5f and so on. But I'm using a class (SettingHelper.cs) to save and read from the IsolatedStorage. And even if I use float all the way through to the IsolatedStorage, it does not work. But I've changed it to int now, and it works fine. It's really not necessary for me to use float (or double) in this case. So, maybe I'll try to look more into it if I need to use decimals, but for this time, I'll just go with the int.

Thank you for great help and support! :)

Coordinator
Apr 11, 2011 at 11:28 AM

Strange. Obviously without seeing the rest of the code I can't help much more. The only thing I can think is that on the way in or out of IsolatedStorage it is getting zeroed for some reason - but if that was the case then I would have thought that storing an int would do the same.

Oh well.

Sam

Apr 11, 2011 at 12:09 PM

Yes, I know. But then I would have to send you the project, so you could look at all the code. I could of course send it to you, if you'd like to take a look...?

Coordinator
Apr 11, 2011 at 3:37 PM

OK, thanks for sending the source code. I changed it back to a float and found the problem.

It seems that Flickr doesn't like a radius if it has more than 5 decimal places - so 5.11111 works fine, but 5.111111 acts as if you passed in zero.

I'll change the library to only output the first 5 decimal places, but in the mean time you can now change your code if you want (or just stick with integers if you prefer).

Sam

Apr 11, 2011 at 5:54 PM

Once more, a big thank you! :)

I'm now using float, and I just used the following code where I set the radius, and now it's working :)

options.Radius = float.Parse(radius.ToString("N5")); //Set it to 5 decimals, the Flickr api reads it as 0 if it's more than 5 decimals            

Coordinator
Apr 11, 2011 at 8:58 PM

You could do that, or you could use (float)Math.Round(radius, 5); which avoids converting it to a string and back again.

Apr 11, 2011 at 9:26 PM

Ah, thanks Sam! I'll do that :)