There's a way to recover a card location? - google-mirror-api

I'm trying the recover the location of a card previously set, so I could replace the HTML card with a map and a route with Glass last location.
But when I get the card back, it has no location. The location is set on card because I tested on Glass and it's all right.
Here's my piece of PHP code:
elseif ($user_action['type'] == 'CUSTOM' && $user_action['payload'] == 'show-in-map')
{
$timeline_item_id = $request['itemId'];
$timeline_item = $mirror_service->timeline->get($timeline_item_id);
$patch = new Google_TimelineItem();
$cardFomater = new Card_Formater($patch->getHtml());
$cardLocation = $timeline_item->getLocation();
$patch->setHtml($cardFomater->replaceHtmlWithMap($location->getLatitude(),$location->getLongitude(),
$cardLocation->getLatitude(),$cardLocation->getLongitude()));
$mirror_service->timeline->patch($timeline_item_id, $patch);
}
It says the $cardLocation does not have the property getLatitude().

Related

How to extract an element of a spreadsheet as a string, not as an array element Google App Script

(Edited the problem description)
What I am trying to do: Using this Spreadsheet to collect the URLs row by row and paste each image in a new slide of a Google Slide named Output Document. I am using a function addImagetoSlide that takes in the imageUrl, the slide number and the name of the document to add images to each element of the slide.
Where I am stuck When I try to use dataRange (the array containing my spreadsheet element, it works well outside the while loop, but inside the while loop, it does not read the element [0][2] saying that "Cannot read Property 2 of line.. I do not understand why it works outside but not inside the while loop
function collateImages(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var targetDocument = SlidesApp.create("Output Document"); // Target file for the collation
var dataRange = sheet.getDataRange(); // Range of the entire database
Logger.log(dataRange.getValues()[0][2]);
Logger.log(dataRange.getValues()[1][2]);
Logger.log(dataRange.getValues()[2][2]);
Logger.log(dataRange.getValues()[3][2]);
var i = 0; // Iterator
while (i< dataRange.getLastRow()){
i = i + 1;
Logger.log(dataRange.getValues()[i][2]);
addImageToSlide(doubtRange.getValues()[i][2],i,targetDocument);
}
}
// Function to get file id from url
function getIdFromUrl(url) { return url.match(/[-\w]{25,}/); }
//Add Image with URl "ImageUrl" on slide number "index on a presentation named "deck"
function addImageToSlide(imageUrl, index,deck) {
var slide = deck.appendSlide(SlidesApp.PredefinedLayout.BLANK);
var imagefile = DriveApp.getFileById(getIdFromUrl(imageUrl));
var imageblob = imagefile.getBlob();
var image = slide.insertImage(imageblob);
}
The problem with the code you have used is that you are trying to access an index that doesn't exist. As you are incrementing the i value on the last loop, when calling the dataRange.getValues()[i][2], this will try to retrieve the element corresponding to the incremented i which falls out of the range, hence the error message you are receiving.
You can:
move the i increment after calling the dataRange.getValues()[i][2];
use a for loop;
Reference
Sheet Class Apps Script - getDataRange().

Swift - Update and store position of a multiple programmatically created buttons

I have a button which creates other buttons based on the class Clip seen below. Those newly created buttons are added to an array and stored in a plist.
class Clip: Encodable, Decodable {
var name: String = ""
var xCoordinate: Int = 100
var yCoordinate: Int = 300
// more parameter will be added later on e.g color, scale etc..
}
Each button can be moved around the view and the new x & y coordinates are stored in a plist.
#objc func handlePan(sender: UIPanGestureRecognizer){
let uIViewSelected = sender.view!
switch sender.state {
case .began, .changed :
moveViewWithPan(view: uIViewSelected, sender: sender)
break
case .ended:
//Finds the position when the button is no longer being dragged
let x = Int(uIViewSelected.center.x)
let y = Int(uIViewSelected.center.y)
//clipArray[0] need to be the corresponding clicked button e.g clipArray[2]
clipArray[0].xCoordinate = x
clipArray[0].yCoordinate = y
saveData()
break
default:
break
}
}
The above works only if I create one button. When more buttons are added, the above lines only change the first clip from the array. I need a way to update the value to the correct button clicked.
How can identify the array position of the click button as I am creating all them programmatically? At the moment I am placing at value 0 of the clipArray.
clipArray[0].xCoordinate = x
clipArray[0].yCoordinate = y
I am not even sure if using a plist is the best way to store the buttons in the first place.
Any help or documentation would be much appreciated.
Thanks
Following from dfd response, I added tags to each button which are created and it solved the issue for now.
let x = Int(uIViewSelected.center.x)
let y = Int(uIViewSelected.center.y)
//clipArray.append(clip)
var tagNo = uIViewSelected.tag
clipArray[tagNo].xCoordinate = x
clipArray[tagNo].yCoordinate = y

Get latitude, longitude from restfb

I used to use fql to get latitude and longitude from Place.
How do I do it nowadays? I've got the user's location, but only id and name are filled in. Everything else is null. Code:
FacebookClient fc = new DefaultFacebookClient(token, Version.VERSION_2_9);
User user = fc.fetchObject("me", User.class, Parameter.with("location"));
Location loc = fc.fetchObject(user.getLocation().getId(), Location.class);
Also tried:
Place pl = fc.fetchObject(user.getLocation().getId(), Place.class);
Same thing.
As I wrote in the RestFB bugtracker:
FacebookClient fc = new DefaultFacebookClient(token, Version.VERSION_2_9);
User user = fc.fetchObject("me", User.class, Parameter.with("fields","location"));
Page pageOfUserLocation = fc.fetchObject(user.getLocation().getId(),
Page.class, Parameter.with("fields","location");
if (pageOfUserLocation.getLocation() != null) {
System.out.println("longitude: ", pageOfUserLocation.getLocation().getLongitude());
System.out.println("latitude: ", pageOfUserLocation.getLocation().getLatitude());
}

How to get current latitude and longitude values in codename one

Im trying to get my current latitude and longitude values using LocationManager in Codename One but the values i'm getting is for a different location.
Here is my code:
LocationManager locationManager = LocationManager.getLocationManager();
Location location = locationManager.getCurrentLocation();
Double loc1= location.getLatitude();
Double loc2= location.getLongitude();
System.out.println("Latitude: "+loc1);
System.out.println("Longitude: "+loc2);
Output:
Latitude: 40.715353
Longitude: -74.00497299999999
My correct current Latitude and Longitude values are 3.xxxx and 101.xxxx respectively.
Please how can I get these correct values from LocationManager?
That is default location on Simulator.
Note that you can't get your actual location on Simulator without entering it yourself.
To set your simulator to use your current location, Click Simulate on your simulator and select Location Simulation. Enter your LatLong values for Available and Click Update. The Google map will shift view to your location, So would your app.
You can keep Location Simulator open while you test your app.
On a side note, if your app needs a real time location I would suggest you use getCurrentLocationAsync(). Below is an example:
InfiniteProgress ip = new InfiniteProgress();
Dialog ipDlg = ip.showInifiniteBlocking();
Location location = LocationManager.getLocationManager().getCurrentLocationSync(30000);
ipDlg.dispose();
if (location == null) {
try {
location = LocationManager.getLocationManager().getCurrentLocation();
} catch (IOException err) {
Dialog.show("Location Error", "Unable to find your current location, please be sure that your GPS is turned on", "OK", null);
return;
}
}
Double loc1 = location.getLatitude();
Double loc2 = location.getLongitude();
Log.p("Latitude: " + loc1);
Log.p("Longitude: " + loc2);

AS3 saving from a timeline to a sharedObject (possible to place in an array)

I was hoping someone could offer a simple solution. I am trying to save a 'labeled' frame on the timeline by storing it as a SharedObject.
The user can flip between various different backgrounds on the stage by clicking a button - button one corresponds to background one, background 2 corresponds to btn two and so on... For your reference these backgrounds are stored in a sub timeline in a movieClip. Any tips on how to get this to store..?
I'm open to new theories as I'm not having a lot of success saving from the movieClip on the time line.
I have already posted a question similar to this but I was wandering if it was possible to store these frames in an array? Array1 = image1 Array2 = image2 and so making it easier to store. I'm guessing I would need to make a loadermodule to store these images on the stage as well.
Thanks
// SAVE FUNCTIONS ---------------------------------------
//---------------------------------------------------
//---------------------------------------------------
var mySO:SharedObject = SharedObject.getLocal("iDesign");
bones_mc.x = mySO.data.my_x;
bones_mc.y = mySO.data.my_y;
if (!mySO.data.my_y) {
bones_mc.x = 424;
bones_mc.y = 119;
}
//----
save_btn.addEventListener (MouseEvent.CLICK, clickersave);
function clickersave (e:MouseEvent):void {
mySO.data.my_x = bones_mc.x;
mySO.data.my_y = bones_mc.y;
mySO.data.mybut_x = btrfly_mc.x;
mySO.data.mybut_y = btrfly_mc.y;
mySO.data.mytig_x = tiger_mc.x;
mySO.data.mytig_y = tiger_mc.y;
mySO.data.mybow_x = pink_bow_mc.x;
mySO.data.mybow_y = pink_bow_mc.y;
mySO.data.myblkbow_y = pink_bow_mc.y;
mySO.data.myblkbow_x = pink_bow_mc.x;
// tears saved - - - - - - -
mySO.data.mytear_drop_mc_three_x = tear_drop_mc_three.x;
mySO.data.mytear_drop_mc_three_y = tear_drop_mc_three.y;
mySO.data.mytear_drop_mc_one_x = tear_drop_mc_one.x;
mySO.data.mytear_drop_mc_one_y = tear_drop_mc_one.y;
mySO.data.mytear_drop_mc_two_x = tear_drop_mc.x;
mySO.data.mytear_drop_mc_two_y = tear_drop_mc.y;
mySO.data.mytear_drop_mc_four_x = tear_drop_mc_four.x;
mySO.data.mytear_drop_mc_four_y = tear_drop_mc_four.y;
mySO.data.myframe = caseSwapper.currentFrame;
trace(caseSwapper.currentFrame)
mySO.flush ();
}
//caseSwapper.currentFrame = mySO.data.myframe;
tear_drop_mc_three.x = mySO.data.mytear_drop_mc_three_x;
tear_drop_mc_three.y = mySO.data.mytear_drop_mc_three_y;
CODE ADDED TO MAKE THE TIMELINE SAVE - - - - - - - - - -
// applied to the clickersave function
mySO.data.myBgFrame = 2;
mySO.flush ();
}
if (mySO.data.myBgFrame){
caseSwapper.gotoAndStop(mySO.data.myBgFrame);
}
Not sure I understood exactly what you mean, but if you use click on button1 for BG1, in the click function you could write:
mySO.myBgFrame = 1;
mySO.flush ();
and than, when you need to set the saved BG:
if (mySO.myBgFrame){
bgMovieClip.gotoAndStop(mySO.myBgFrame);
}
Is this what you need?

Resources