How to add Info Box in Bing map Controll? - windows-phone-7

I have a Bing map Controll on my form and this bing map contains so many pushpins.
When I click on pushpin at that time i want to show an info box.
So how can I add this info box?
please see bellow image.i have to requery this type of info box.

Here is a sample code. All you have to do is attach a Tap event to the pushpin
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
InitPage();
}
private void InitPage()
{
testMap.Center = new GeoCoordinate(42,42);
testMap.ZoomLevel = 10;
MapLayer pushPinLayer = new MapLayer();
testMap.Children.Add(pushPinLayer);
Pushpin pushpin = new Pushpin();
pushpin.Tap += new EventHandler<GestureEventArgs>(pushpin_Tap);
pushpin.Content = "SAMPLE";
pushPinLayer.AddChild(pushpin, new GeoCoordinate(42, 42));
}
void pushpin_Tap(object sender, GestureEventArgs e)
{
MessageBox.Show("You Clicked here");
}
}

yes i got what are you saying
you just put image button over all the geocoordination
from that you replace the pushpin in place of image buton when any button is press
and dynamically change the content of pushpin in every points

Related

FontAwesome icon with normal text in Xamarin

I want to make a button that has a small icon (from FontAwesome) and text on it in my Xamarin app. I know I can just make a button but the problem is that I will require two fonts (the standard font for text and FontAwesome for the icon). Would anyone happen to know how I can do this, or if there is another way to achieve what I want?
Thanks!
As the json mentioned, I just made a simple implementation.
Create a new class inherit from Label, set FormattedText to combine the string(standard and icon), and add tap gesture on it .
public class MyLabel : Label
{
public delegate void MyHandler(object sender, EventArgs e);
public event MyHandler myEvent;
public MyLabel(string _myIcon, string _myText)
{
//build the UI
FormattedString text = new FormattedString();
text.Spans.Add(new Span { Text = _myIcon ,FontFamily= "FontAwesome5Free-Regular" });
text.Spans.Add(new Span { Text = _myText, TextColor = Color.Red ,BackgroundColor = Color.Blue });
FormattedText = text;
//tap event
TapGestureRecognizer tap = new TapGestureRecognizer();
tap.Tapped += (sender,e) => {
myEvent(sender,e);
};
}
}
Usage
MyLabel label = new MyLabel("", "test");
label.myEvent += (sener,e) =>
{
//do something when tapping
};
Content = label;
For how to integrate FontAwesome in Xamarin.Forms ,refer to
https://montemagno.com/xamarin-forms-custom-fonts-everywhere/.

Xamarin Native map point open infowindow by default

Im loading a native map application (android,IOS) with a custom pin location and with a custom marker.What i need is when i load the map i need to open the map pin marker info window by default.
currently what is happening is when user tap the pin info then only the pin info window shows up.
I have seen some code there markerOpt1.showInfoWindow() there is no method like this.
As per the documentation i know only one info window can pops up.In my scenario only one pin is there
Android implementation
public void OnMapReady(GoogleMap map)
{
MarkerOptions markerOpt1 = new MarkerOptions();
markerOpt1.SetPosition(new LatLng(50.379444, 2.773611));
markerOpt1.SetTitle("Vimy Ridge");
var bmDescriptor = BitmapDescriptorFactory.DefaultMarker (BitmapDescriptorFactory.HueCyan);
markerOpt1.InvokeIcon(bmDescriptor);
map.AddMarker(markerOpt1);
}
I have write custom renders for Android native application markers and ios mkmapview how can i show up the information view when loading the map
Here is the official sample of customrenderers-map-pin, to open infowindow by default,
In iOS:
protected override void OnElementChanged(ElementChangedEventArgs<View> e)
{
base.OnElementChanged(e);
//...
if (e.NewElement != null)
{
var formsMap = (CustomMap)e.NewElement;
var nativeMap = Control as MKMapView;
customPins = formsMap.CustomPins;
//...
//add MapLoaded Event
nativeMap.MapLoaded += NativeMap_MapLoaded;
}
}
And in NativeMap_MapLoaded:
private void NativeMap_MapLoaded(object sender, EventArgs e)
{
annotationView.SetSelected(true,true);
}
In Android, try this:
protected override void OnMapReady(GoogleMap map)
{
base.OnMapReady(map);
MarkerOptions markerOpt1 = new MarkerOptions();
markerOpt1.SetPosition(new LatLng(50.379444, 2.773611));
markerOpt1.SetTitle("Vimy Ridge");
var bmDescriptor = BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueCyan);
Marker marker = map.AddMarker(markerOpt1);
marker.ShowInfoWindow();
}

How to load image onto a button in xamarin forms PCL?

I am picking a photo from photo library and i get the following
AlbumPath:
assets-library://asset/asset.JPG?id=106E99A1-4F6A-45A2-B320-B0AD4A8E8473&ext=JPG
Path:
/Users/myname/Library/Developer/CoreSimulator/Devices/21CB035B-A738-4F74-B121-2DB2A6B5372A/data/Containers/Data/Application/3081A323-98AF-4EF6-95B9-29D4C2CD8425/Documents/temp/IMG_20170408_111143.jpg
How do i assign this image to a button ? I tried the following.
var file = await CrossMedia.Current.PickPhotoAsync(
new Plugin.Media.Abstractions.PickMediaOptions
{
});
Button btn = new Button();
btn.Image = (Xamarin.Forms.FileImageSource)ImageSource.FromFile(file.Path);
No image is displayed on the button. Any help help is appreciated.
Thank you.
Once you deploy the application the app will not have access to your mac. For the application to use the picture it will need to be a bundled resource within the iOS application. Below is a simple example of using images within an iOS app. You'll definitely want to consider just adding a gesture listener to your image instead of making it a button though. If you try to just use the image on a button you'll have to do some styling adjustments to get it to look clean.
Image Setup
Put image in iOS Resource folder
Make sure bundledresource is selected from image properties.
Image Button
public class ImageButton : ContentPage
{
private Button _imageBtn = new Button { Image = "icon.png", Text = "Sample button" };
public ImageButton()
{
Content = new StackLayout
{
Children =
{
_imageBtn
}
};
}
}
Image with TapGesture
public class ImageButton : ContentPage
{
private Image _imageBtn = new Image { Source = "icon.png" };
private TapGestureRecognizer _imageTap = new TapGestureRecognizer();
public ImageButton()
{
_imageBtn.GestureRecognizers.Add(_imageTap);
Content = new StackLayout
{
Children =
{
_imageBtn
}
};
_imageTap.Tapped += (s, e) =>
{
// handle the tap
};
}
}

How to give image to a pushpin dynamically in c#

I have a scenario where I would like the user to view multiple pushpins in Bing maps in a wp7 app. I used maplayer to make the cluster of pushpins, but I could not add an image to that pushpin dynamically in the cs file itself. By the way, I have not used the pushpin control in xaml. I'm just adding the pushpin object to the maplayer while looping through.
Here is my code:
maplayer layer = new maplayer();
watcher.start();
for (int i = 0; i < lst.count; i++)
{
Pushpin mypin = new Pushpin();
watcher.Position.Location.Latitude = Convert.ToDouble(lst[i].Latitude);
watcher.Position.Location.Longitude=Convert.ToDouble(lst[i].Longitude);
}
GeoCoordinate geo = new GeoCoordinate(watcher.Position.Location.Latitude, watcher.Position.Location.Longitude);
mypin.Location = geo;
mypin.Background = new SolidColorBrush(Colors.Gray);
mypin.Foreground = new SolidColorBrush(Colors.White);
mypin.Content = "My location";
layer.AddChild(mypin, mypin.Location);
}
map1.SetView(watcher.Position.Location, Status == true ? 5.0 : 3.0);
map1.Children.Add(layer);
watcher.stop();
I have also tried using the image brush property to provide image source to pushpin but the pushpin itself goes invisible.
like this:
ImageBrush ib = new ImageBrush();
ib.ImageSource = new System.Windows.Media.Imaging.BitmapImage(new Uri(#"Images/push.png", UriKind.Relative));
mypin.Background = ib;
Please help me on this. I need this to be done without changing/adding datatemplate to pushpin from the xaml side.
This problem is covered in MSDN, on the page for Working With Pushpins. Here is the example given, where images are added directly to a layer on the map:
namespace WindowsPhoneApplication1
{
public partial class MainPage : PhoneApplicationPage
{
MapLayer imageLayer;
public MainPage()
{
InitializeComponent();
//Create a layer to contain the pushpin images.
imageLayer = new MapLayer();
map1.Children.Add(imageLayer);
}
private GeoCoordinate mapCenter;
private void button1_Click(object sender, RoutedEventArgs e)
{
// Retrieve the center of the current map view.
mapCenter = map1.Center;
// Define the image to use as the pushpin icon.
Image pinImage = new Image();
//Define the URI location of the image.
pinImage.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("bluepushpin.png", UriKind.Relative));
//Define the image display properties.
pinImage.Opacity = 0.8;
pinImage.Stretch = System.Windows.Media.Stretch.None;
// Put the image at the center of the view.
PositionOrigin position = PositionOrigin.Center;
imageLayer.AddChild(pinImage, mapCenter, position);
}
}
}

Show applicationbar menu programmatically (wp7)

I have a wp7 with some buttons in the application bar.
When each button is pressed I change the menuItems of the application bar's menu.
After this, I want to automatically open the menu when an application bar button is pressed.
But it seems that the SDK doesn't allow me to do that.
Do you know any work around?
I was thinking, if the above is not possible, to simulate a user finger click at the bottom right corner of the screen to open the menu. Any ideas on that?
Thanx in advance
It's possible to change the Application Bar Menu Items in response to an Icon Button click as demonstrated in the code below.
There isn't a way to forcibly open (or close) the application bar through code through.
It also isn't possible to simulate a finger click on the application bar as this isn't part of the actual page. Note that even if possible any click would need to be in the top right or bottom left if the device was in a landscape orientation.
Here's some code which demonstrates changing the menu items:
public partial class MainPage : PhoneApplicationPage
{
private ApplicationBar appbar;
public MainPage()
{
InitializeComponent();
Loaded += new RoutedEventHandler(MainPage_Loaded);
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
appbar = new ApplicationBar();
var ib1 = new ApplicationBarIconButton(new Uri("/images/one.png", UriKind.Relative)) { Text = "Option one" };
ib1.Click += new EventHandler(ShowMenuOption1);
var ib2 = new ApplicationBarIconButton(new Uri("/images/two.png", UriKind.Relative)) { Text = "Option two" };
ib2.Click += new EventHandler(ShowMenuOption2);
appbar.Buttons.Add(ib1);
appbar.Buttons.Add(ib2);
// Show menu option 1 as default
DisplayMenuOption1();
this.ApplicationBar = appbar;
}
private void DisplayMenuOption1()
{
appbar.MenuItems.Clear();
var itemA = new ApplicationBarMenuItem("AAAA");
var itemB = new ApplicationBarMenuItem("BBB");
appbar.MenuItems.Add(itemA);
appbar.MenuItems.Add(itemB);
}
private void DisplayMenuOption2()
{
appbar.MenuItems.Clear();
var itemC = new ApplicationBarMenuItem("CCCC");
var itemD = new ApplicationBarMenuItem("DDDD");
appbar.MenuItems.Add(itemC);
appbar.MenuItems.Add(itemD);
}
private void ShowMenuOption2(object sender, EventArgs e)
{
DisplayMenuOption2();
}
private void ShowMenuOption1(object sender, EventArgs e)
{
DisplayMenuOption1();
}
}
As far as I'm aware this capability has not been exposed as yet. It wasn't possible during beta and I've not noticed anything that's changed since that would allow it. You could always comment on the their suggestions forum or raise it on connect (vs/wpdt).

Resources