I have a map with a single pin on it. as follows:
var map = new Map()
{
IsShowingUser = true,
HeightRequest = 100,
WidthRequest = 960,
VerticalOptions = LayoutOptions.FillAndExpand
};
and the pin location and label as follows:
var pin1 = new Pin();
pin1.Type = PinType.Place;
pin1.Position = position;
pin1.Label = "Ticket Number: " + Cache.Instance.Ticket.TicketNumber;
clicked event:
pin1.Clicked += delegate
{
uri = new Uri("http://maps.google.com/maps?daddr=" + position.Latitude + "," + position.Longitude);
Device.OpenUri(uri);
}
map loading:
var stack = new StackLayout { Spacing = 00 };
stack.Children.Add(map);
Content = stack;
when clicking on the pin marker, it opens an info window and clicking on the window and clicked event code triggers. It there any way to not show the info window and the event triggers as soon as I click on the marker?
Thanks
Use Map_PinClicked to handle the PinClick event, If you set e.Handled = true, then Pin selection doesn't work automatically. All pin selection operations are delegated to you.
In the Page:
map.PinClicked += Map_PinClicked;
// Selected Pin changed
map.SelectedPinChanged += SelectedPin_Changed;
map.InfoWindowClicked += InfoWindow_Clicked;
map.InfoWindowLongClicked += InfoWindow_LongClicked;
And then clickEvent:
void Map_PinClicked(object sender, PinClickedEventArgs e)
{
e.Handled = true;
uri = new Uri("http://maps.google.com/maps?daddr=" + position.Latitude + "," + position.Longitude);
Device.OpenUri(uri);
}
You can have a look at here for more information.
Currently with Xamarin.Forms 5, PinClicked event is designated as obsolete. Same goes for Device.OpenUri.
One can use pin1.MarkerClicked += Pin_Clicked; instead.
You can prevent the Info window from opening by setting the EventArgs's HideInfoWindow property to true.
docs.microsoft
private async void Pin_Clicked(object sender, PinClickedEventArgs e)
{
try
{
e.HideInfoWindow = true;
var pin = sender as Pin;
var uri = new Uri("http://maps.google.com/maps?daddr=" + pin.Position.Latitude + "," + pin.Position.Longitude);
Launcher.OpenAsync(uri);
}
catch (Exception ex)
{
//log error
}
}
Related
I have a problem. I have a short list of clients and for each of them I want to display a pin and Popup window, which will be displayed after clicking the info window. However, I have no idea how to connect it.
Part of my code:
List<Client> lstClients = new List<Client>
{
new Client(1, "Firma 1", "Wspólna 10", "123-123-23-23", "F1", true),
new Client(2, "Firma 2", "Marszałkowska", "456-456-56-45", "F2", false),
new Client(3, "Firma 3", "Jerozolimskie 57", "789-789-89-78", "F3", true),
new Client(4, "Firma 4", "Koszykowa 10", "234-423-43-23", "F4", false)
};
foreach (Client client in lstClients)
{
var geoadres = client.Address;
var locations = await Geocoding.GetLocationsAsync(client.Address);
var location = locations?.FirstOrDefault();
ListPin = new Pin
{
Type = PinType.Place,
Label = client.FirmName,
Address = client.Address,
Position = (new Position(location.Latitude, location.Longitude)),
Rotation = 33.3f,
Tag = client.Tag
};
map.Pins.Add(ListPin);
}
void InfoWindow_Clicked(object sender, InfoWindowClickedEventArgs e)
{
PopupNavigation.Instance.PushAsync(new ShowPopup());
}
I will be grateful for any help.
By clicking on the pin need to show the pop up window, you can implement like this;
foreach (Client client in lstClients)
{
var geoadres = client.Address;
var locations = await Geocoding.GetLocationsAsync(client.Address);
var location = locations?.FirstOrDefault();
ListPin = new Pin
{
Type = PinType.Place,
Label = client.FirmName,
Address = client.Address,
Position = (new Position(location.Latitude, location.Longitude)),
Rotation = 33.3f,
Tag = client.Tag
};
map.Pins.Add(ListPin);
// tap event from map pinview -> Callout action
map.Pins[i].Clicked += (sender, e) =>
{
System.Diagnostics.Debug.WriteLine(((Pin)sender).Type);
DisplayAlert(((Pin)sender).Label, ((Pin)sender).Address, "OK");
};
}
add the code inside for-loop
I am making a game on cocos2d-JS for facebook in which there is a requirement of sharing a screenshot of the game.
I am able to take the screenshot but now I am unable to upload it in the Parse.com server because it requires base64 format or byte array. I am unable to find any solution of converting Sprite in to this format.. Here's my code so result when I do addchild its coming proper .. I have also added my commented code so that it will help to understand that I have tried lot of things but couldnt achieve the same.
shareToSocialNetworking: function () {
cc.director.setNextDeltaTimeZero(true);
var newsize = cc.director.getVisibleSize();
var renderText = new cc.RenderTexture(newsize.width,newsize.height);
renderText.begin();
cc.director.getRunningScene().visit();
renderText.end();
var result = cc.Sprite.create(renderText.getSprite().getTexture());
result.flippedY = true;
this._mainViewNode.addChild(result,6000);
//renderText.saveToFile("screenshot.jpg",cc.IMAGE_FORMAT_PNG);
//var based = renderText.getSprite().getTexture().getStringForFormat().toString();
//var data = based.getData();
var file = new Parse.File("screen.jpg", { base64: this.getBase64(result) });
//var file = new Parse.File("screen.jpg", data, "image/png");
var self = this;
file.save().then(function() {
// The file has been saved to Parse.
alert(file.url);
this.onSharePictureInfoLink(file.url());
}, function(error) {
// The file either could not be read, or could not be saved to Parse.
});
//
//var ccImage = renderText.newCCImage();
//
//var str = ccImage.getData();
},
is there any workaround that can be done
there is a private variable called _cacheCanvas, which is the instance of the offscreen canvas
you can simply do renderText._cacheCanvas.toDataURL()
Here's how you can take the screnshot from cocos2d-JS
screenshot: function (fileName) {
var tex = new cc.RenderTexture(winSize.width, winSize.height, cc.Texture2D.PIXEL_FORMAT_RGBA8888);
tex.setPosition(cc.p(winSize.width / 2, winSize.height / 2));
tex.begin();
cc.director.getRunningScene().visit();
tex.end();
var imgPath = jsb.fileUtils.getWritablePath();
if (imgPath.length == 0) {
return;
}
var result = tex.saveToFile(fileName, cc.IMAGE_FORMAT_JPEG);
if (result) {
imgPath += fileName;
cc.log("save image:" + imgPath);
return imgPath;
}
return "";
}
then make a Java call from Javascript
public static void ScreenShot()
{
Bitmap imageBitmap = BitmapFactory.decodeFile(Cocos2dxHelper.getCocos2dxWritablePath() + "/" + "screenshot.png");
String fileHolder = "SampleFolder";
File filepathData = new File("/sdcard/" + fileHolder);
//~~~Create Dir
try {
if (!filepathData.exists())
{
filepathData.mkdirs();
filepathData.createNewFile();
FileWriter fw = new FileWriter(filepathData + fileHolder);
BufferedWriter out = new BufferedWriter(fw);
String toSave = String.valueOf(0);
out.write(toSave);
out.close();
}
}
catch (IOException e1) {
}
//~~~Create Image
File file = new File("/sdcard/" + "Your filename");
try
{
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
imageBitmap.compress(CompressFormat.PNG, 100, ostream);
ostream.close();
}
catch (Exception e) {}
Uri phototUri = Uri.fromFile(file);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, phototUri);
//~~~Add Code Below
}
Do not forget to add permission for external storage
I am working on a wp8 project and need to find the location . I've used windows.device.geoloaction name space to find the lattitude and longitude now I need to find the address(country state and zip). I found this example but I am confused how to pass the coordinates that I obtained . Here is my code.
public async void FindTADeviceLocation()
{
////Declare Geolocator object
Geolocator geolocator = new Geolocator();
// Set user's accuracy
geolocator.DesiredAccuracy = PositionAccuracy.High;
//get the position of the user.
try
{
//The await guarantee the calls to be returned on the thread from which they were called
Geoposition geoposition = await geolocator.GetGeopositionAsync(
maximumAge: TimeSpan.FromMinutes(1),
timeout: TimeSpan.FromSeconds(10)
);
var geoQ = new ReverseGeocodeQuery();
geoQ.QueryCompleted += geoQ_QueryCompleted;
if (geoQ.IsBusy == true)
{
geoQ.CancelAsync();
}
// Set the geo coordinate for the query
geoQ.GeoCoordinate = geoposition.Coordinate;
geoQ.QueryAsync();
}
catch (Exception ex)
{
if ((uint)ex.HResult == 0x80004004)
{
MessageBox.Show("position is unknown");
}
}
}
void geoQ_QueryCompleted(object sender, QueryCompletedEventArgs<IList<MapLocation>> e)
{
if (e.Result.Count() > 0)
{
string showString = e.Result[0].Information.Name;
showString = showString + "\nAddress: ";
showString = showString + "\n" + e.Result[0].Information.Address.PostalCode + " " + e.Result[0].Information.Address.City;
showString = showString + "\n" + e.Result[0].Information.Address.Country + " " + e.Result[0].Information.Address.CountryCode;
showString = showString + "\nDescription: ";
showString = showString + "\n" + e.Result[0].Information.Description.ToString();
MessageBox.Show(showString);
}
}
I know the problem is in the line geoQ.GeoCoordinate = geoposition.Coordinate;
But how can I pass the coordinates to geoQ.GeoCoordinate?
Thanks in adwance
This is done. The geocordinate takes arguments of the type double. so all we've to do is to convert the cordiantes into double and pass it.
var currentLocationLatitude = Convert.ToDouble(geoposition.Coordinate.Latitude.ToString("0.0000000000000"));
var currentLocationLongitude = Convert.ToDouble(geoposition.Coordinate.Longitude.ToString("0.0000000000000"));
var geoQ = new ReverseGeocodeQuery();
geoQ.QueryCompleted += geoQ_QueryCompleted;
if (geoQ.IsBusy == true)
{
geoQ.CancelAsync();
}
// Set the geo coordinate for the query
geoQ.GeoCoordinate = new GeoCoordinate(currentLocationLatitude, currentLocationLongitude);
geoQ.QueryAsync();
Thanks
I have this .swf file: http://www.mediafire.com/download/hrr3c6c188jsgvd/upload.swf
I need to change something in this file, so I have this website http://www.showmycode.com/ decode the file and got those code:
if (!hasOwnProperty("_load05626E90")) {
_load05626E90 = true;
telltarget ("..") {
var copyright = function () {
telltarget ("..") {
geturl("http://www.google.com/search?q=PHP+Script+c-Image+Uploader+3.0", "_blank");
}
};
}
}
else {
// unexpected jump
}
var author = function () {
telltarget ("..") {
geturl("http://chiplove.biz", "_blank");
}
};
// unexpected jump
// unexpected jump
var uploadItem = function (num) {
telltarget ("..") {
var item = flash.net.FileReference(list[num]);
item.addlistener(listener2);
item.upload((((((((((("upload.php?watermark=" + watermark) + "&logo=") + logo) + "&resize=") + resize) + "&server=") + server) + "&q=") + q)+ "&account=") + account)+ "&password=") + password);
}
};
// unexpected jump
// unexpected jump
var FileChooser = function () {
telltarget ("..") {
var fileRef = new flash.net.FileReferenceList();
fileRef.addlistener(listener);
fileRef.browse(allTypes);
}
};
// unexpected jump
// unexpected jump
};
stop();
//---------------------------------------------------------------------- //Frame 1 //----------------------------------------------------------------------
this.menu = new contextmenu();
this.menu.hidebuiltinitems();
this.menu.customitems.push(new contextmenuitem("PHP Script - c-Image Uploader 3.0", copyright));
this.menu.customitems.push(new contextmenuitem("Powered by chiplove.9xpro", author));
//---------------------------------------------------------------------- //Symbol 3 Button //----------------------------------------------------------------------
on (press) {
var listener = new object();
var listener2 = new object();
var itemnum = 0;
var numfiles = 0;
delete _global.__resolve;
_global.__resolve = _global.__debugResolve;
if (list == undefined) {
var list = null;
}
var allTypes = new array();
var imageTypes = new object();
imageTypes.description = "Images (*.jpg; *.jpeg; *.jpe; *.gif; *.png;)";
imageTypes.extension = "*.jpg; *.JPG; *.jpeg; *.jpe; *.gif; *.png;";
allTypes.push(imageTypes);
listener.onselect = function (fileRefList) {
list = fileRefList.fileList; numfiles = list.length;
uploadItem(itemnum);
};
listener2.onOpen = function (file) { };
listener2.onProgress = function (file, bytesloaded, bytestotal) {
flash.external.ExternalInterface.call("loading");
};
listener2.onComplete = function (file) { };
listener2.onUploadCompleteData = function (file, data) {
var loadvars = new loadvars();
loadvars.decode(data);
flash.external.ExternalInterface.call("displaypic", file.name, loadvars.image);
itemnum = itemnum + 1;
if (itemnum < numfiles) {
uploadItem(itemnum);
}
else {
flash.external.ExternalInterface.call("responseStatus", "Done!");
}
};
flash.external.ExternalInterface.addCallBack("FileChooser", this, FileChooser);
flash.external.ExternalInterface.call("clearlist");
FileChooser();
}
I think this is Action Script code, so after make some little change I get flash builder to recompile it, however, flash builder show a lot of red underline (syntax error) in my code and can't build those code to .swf file again. I wonder if the code I got from showmycode.com is correct, or is it action script? If the code I got from showmycode.com is not correct, how can I decode, edit, then encode again that "upload.swf" file?
I am interested in displaying an input dialog and once the user enters the name of the node in the dialog I would like to create a tree node with the name they entered.
I am creating the edit dialog and then adding the node all in the same function but the behavior that I am seeing is that the tree node appears before the dialog appears or before the user even gets a chance to submit the name for the node, meaning the rest of the code that is included after displaying the dialog doesn't wait for the dialog to return the input.
Is there a way to provide an input dialog and wait for completion before taking another action?
Here is my code - The add() method calls editKey() method and then adds the node.
I expected to be able to wait for the input for each key and build the tag name before the rest of the code in the add function continues but that appears not to be the case:
public void add(){
log.debug("node=<" + node.getValue() + ">");
Node saveNode = node;
if (node.getInfo().isList() ||
node.getInfo().isLeafList()){
try{
TreeHelper treeHelper = (TreeHelper)device.getTreeHelper();
Node n = treeHelper.getSchemaNode(node, node.getTagPath());
if (n != null){
if (node.getInfo().isList()){
log.debug("node<" + node.getName() + " is a list!");
String tagName = "";
if (n.getKeys().size() > 0){
for(String key: n.getKeys()){
node = n.getChildren().get(key);
if (node != null){
editKey(node);
}
if (tagName.equals("")){
tagName += node.getValue();
}else{
tagName += "-" + node.getValue();
}
}
}
n.setTag(tagName);
n.getInfo().setListEntry(true);
n.getNodeTypes().remove("List");
n.getNodeTypes().add("ListEntry");
node = saveNode;
}else if (node.getInfo().isLeafList()){
log.debug("node <" + node.getName() + "> is a leaf list!");
n.getInfo().setLeafListEntry(true);
n.getNodeTypes().remove("LeafList");
n.getNodeTypes().add("LeafListEntry");
}
addTreeNode(this.device,
selectedNode,
n,
true,
true);
}else{
log.debug("schema node is null for node <" + node.getName() + ">");
}
}catch(Exception e){
log.error(IO.stackTrace(e));
}
selectedNode.setExpanded(true);
}
RequestContext.getCurrentInstance().update("treeForm:treeSingle");
}
Here is the editKey() function:
public void editKey(Node node) throws Exception{
FacesContext ctx = FacesContext.getCurrentInstance();
UIViewRoot rootView = ctx.getViewRoot();
Dialog dialog = (Dialog)rootView.findComponent("editDialog");
dialog.setVisible(true);
dialog.setModal(true);
dialog.getChildren().clear();
UIForm form = new UIForm();
form.getChildren().clear();
PanelGrid panel = new PanelGrid();
panel.setColumns(2);
OutputLabel label = new OutputLabel();
label.setValue(node.getName());
label.setFor("valueId");
panel.getChildren().add(label);
if (node.getDataTypes().contains("BOOL") ||
(node.getValue() != null &&
(node.getValue().equals("false") || node.getValue().equals("true")))){
SelectOneMenu menu = new SelectOneMenu();
ValueExpression valueExpression = createValueExpression("#{treeBean.node.value}");
menu.setValueExpression("value", valueExpression);
menu.setId("valueId");
menu.setLabel(node.getName());
if (node.getValue() != null &&
node.getValue().equals("false")){
UISelectItem item = new UISelectItem();
item.setItemLabel("false");
item.setItemValue("false");
menu.getChildren().add(item);
item = new UISelectItem();
item.setItemLabel("true");
item.setItemValue("true");
menu.getChildren().add(item);
}else{
UISelectItem item = new UISelectItem();
item.setItemLabel("true");
item.setItemValue("true");
menu.getChildren().add(item);
item = new UISelectItem();
item.setItemLabel("false");
item.setItemValue("false");
menu.getChildren().add(item);
}
panel.getChildren().add(menu);
}else if (node.getEnums().size() > 0){
SelectOneMenu menu = new SelectOneMenu();
ValueExpression valueExpression = createValueExpression("#{treeBean.node.value}");
menu.setValueExpression("value", valueExpression);
menu.setId("valueId");
menu.setLabel(node.getName());
for(String s : node.getEnums()){
int index = s.indexOf(":");
if (index != -1){
s = s.substring(0, index);
}
UISelectItem item = new UISelectItem();
item.setItemLabel(s);
item.setItemValue(s);
menu.getChildren().add(item);
}
panel.getChildren().add(menu);
}else{
InputText inputText = new InputText();
ValueExpression valueExpression = createValueExpression("#{treeBean.node.value}");
inputText.setValueExpression("value", valueExpression);
inputText.setId("valueId");
inputText.setLabel(node.getName());
inputText.setType("text");
panel.getChildren().add(inputText);
}
UIOutput output = new UIOutput();
output.setValue("Data types: ");
panel.getChildren().add(output);
output = new UIOutput();
output.setValue(node.getDataTypes().toString().replace("]", "").replace("[", ""));
panel.getChildren().add(output);
output = new UIOutput();
output.setValue("Min. occurs: ");
panel.getChildren().add(output);
output = new UIOutput();
output.setValue(node.getMinOccurs()+"");
panel.getChildren().add(output);
output = new UIOutput();
output.setValue("Max. occurs: ");
panel.getChildren().add(output);
output = new UIOutput();
output.setValue(node.getMaxOccurs()+"");
panel.getChildren().add(output);
form.getChildren().add(panel);
CommandButton button = new CommandButton();
button.setOnclick("$('#progress').show();$('#editDialog').hide();");
button.setOncomplete("$('#progress').hide();$('#editDialog').hide();");
button.setValue("submit");
MethodExpression me = createMethodExpression("#{treeBean.save}");
button.setActionExpression(me);
form.getChildren().add(button);
dialog.getChildren().add(form);
RequestContext.getCurrentInstance().update("editDialog");
RequestContext.getCurrentInstance().execute("editWidget.show()");
}