Centered Fixed Marker on Xamarin.Forms.Maps - google-maps

I'm trying to integrate a map on Xamarin.Forms that when opened, a fixed marker is placed on the center of the map. By fixed, I mean it does not move when the map is dragged and the marker itself is also not draggable. Can somebody guide me through this or do you have any reference that I can read on? I already have the map displayed.

Don't add a marker to the map, but instead overlay the map with a view on top of it.

I had this same problem and after searching for very long, I finally combined some parchments and logic to arrive at a solution that FINALLY WORKED. I posted a COMPLETE SOLUTION to the Centred Marker problem on Github, here is the link.
https://github.com/amay077/Xamarin.Forms.GoogleMaps/issues/486
but for the purpose of redundancy (in case you can't find the post for one reason or the other), here is the solution
<AbsoluteLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<StackLayout x:Name="PanelMain" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1">
<StackLayout HorizontalOptions="CenterAndExpand" VerticalOptions="Start">
<StackLayout HorizontalOptions="FillAndExpand" Orientation="Vertical" VerticalOptions="Start" Padding="10,0,10,0">
<Label x:Name="lblTotal" FontSize="14" TextColor="Black" FontAttributes="Bold" HorizontalTextAlignment="Center" Text="[Address Show Here]" />
<Label x:Name="lblCoordinates" VerticalTextAlignment="Center" FontSize="12" HorizontalTextAlignment="Center" Text="[GPS Coordinates]" />
<SearchBar x:Name="SearchTextBox" TextColor="Black" HorizontalOptions="FillAndExpand" CancelButtonColor="Red" SearchButtonPressed="SearchTextBox_SearchButtonPressed" Placeholder="Search for Destination"></SearchBar>
<ActivityIndicator IsVisible="False" x:Name="MyActivityIndicator" Color="#039763" IsRunning="False"></ActivityIndicator>
</StackLayout>
</StackLayout>
<StackLayout x:Name="mystacklayout" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
</StackLayout>
<StackLayout BackgroundColor="White" Orientation="Vertical" HorizontalOptions="FillAndExpand">
<StackLayout BackgroundColor="White" Orientation="Vertical" HorizontalOptions="FillAndExpand" Padding="10">
<synbtn:SfButton x:Name="cmdGetCoordinateDestination" CornerRadius="7" BackgroundColor="#E66C2C" BorderColor="#039763" HasShadow="False" TextColor="White" FontSize="14" HeightRequest="42" Text="Get GPS Coordinates" Clicked="cmdGetCoordinateDestination_Clicked"></synbtn:SfButton>
<synbtn:SfButton x:Name="cmdSUBMIT" CornerRadius="7" IsVisible="False" IsEnabled="True" BorderColor="LightGray" HasShadow="False" BackgroundColor="#039763" TextColor="White" FontSize="16" HeightRequest="45" Text="SUBMIT REPORT" Clicked="CreateAccountClicked"></synbtn:SfButton>
<!--<Label x:Name="lbldistance" Text="Within 50 Kilometers (KM)" HorizontalTextAlignment="Center" TextColor="Black" FontSize="11" />
<syncslider:SfRangeSlider x:Name="theSlider" HeightRequest="60" ShowRange="False" SnapsTo="StepValues" StepFrequency="20" Orientation="Horizontal" HorizontalOptions="CenterAndExpand" TickPlacement="Inline" ValueChangeMode="Default" Minimum="0" Maximum="300" Value="50" ValueChanging="theSlider_ValueChanging"></syncslider:SfRangeSlider>-->
</StackLayout>
</StackLayout>
</StackLayout>
<StackLayout x:Name="mycentremarker_layout" IsVisible="True" Padding="12"
AbsoluteLayout.LayoutFlags="PositionProportional"
AbsoluteLayout.LayoutBounds="0.5,0.5,-1,-1">
</StackLayout>
</AbsoluteLayout>
Now, combine this with some C# code for adding and initializing the Xamarin.Forms.Map and the Centre Marker Icon to the page
private async void PrepareMap()
{
try
{
var request = new GeolocationRequest(GeolocationAccuracy.Medium);
var location = await Geolocation.GetLocationAsync(request).ConfigureAwait(true);
if (location != null)
{
App.lastlatitude = location.Latitude; //double.Parse("8.13463");
App.lastlongitude = location.Longitude; //double.Parse("-13.30254");
}
if (App.lastlatitude != 0)
{
var position = new Position(App.lastlatitude, App.lastlongitude);
customMap = new CustomMap
{
MapType = MapType.Street,
IsShowingUser = true,
WidthRequest = 100,
HeightRequest = 100,
VerticalOptions = LayoutOptions.FillAndExpand
};
customMap.MapType = MapType.Street;
customMap.TrafficEnabled = true;
if (mystacklayout.Children.Any())
{
mystacklayout.Children.Clear();
}
mystacklayout.Children.Add(customMap);
customMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(App.lastlatitude, App.lastlongitude), Distance.FromMiles(5)));
customMap.IsShowingUser = true;
TheCoordinates = App.lastlatitude + ", " + App.lastlongitude;
var thelatdecimal = App.lastlatitude.ToString().Split('.')[1];
var thelongdecimal = App.lastlongitude.ToString().Split('.')[1];
if (thelatdecimal.Length > 5)
{
thelatdecimal = thelatdecimal.Substring(0, 5);
}
if (thelongdecimal.Length > 5)
{
thelongdecimal = thelongdecimal.Substring(0, 5);
}
var thelat = App.lastlatitude.ToString().Split('.')[0] + "." + thelatdecimal;
var thelong = App.lastlongitude.ToString().Split('.')[0] + "." + thelongdecimal;
lblCoordinates.Text = thelat + ", " + thelong;
AddTheCentreMarker();
}
}
catch (Exception ex)
{
await DisplayAlert("Error", ex.Message, "OK").ConfigureAwait(true);
}
}
private async void AddTheCentreMarker()
{
try
{
Image _imgMarker = new Image(); //marker holder declaration
int int_markerSize; //marker sizer
_imgMarker.Source = Device.OnPlatform(
iOS: ImageSource.FromUri(new Uri("http://www.launchappy.com/images/Marker.png")),
Android: ImageSource.FromFile("Marker.png"),
WinPhone: ImageSource.FromFile("Marker.png"));
_imgMarker.VerticalOptions = LayoutOptions.CenterAndExpand;
int_markerSize = 20;
_imgMarker.WidthRequest = int_markerSize;
_imgMarker.HeightRequest = int_markerSize;
mycentremarker_layout.Children.Add(_imgMarker);
}
catch (Exception ex)
{
throw;
}
}
Hope this helps to solve the problem

Related

Bind a span of a FormattedString of a Label in Xamarin Forms at runtime

In Xamarin Forms i want to create formated label inside a collectionView. The label will be created based on many values from a ItemArray.
If i create the label in design using xaml it is working fine:
<Label VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand">
<Label.FormattedText>
<FormattedString>
<Span Text="{Binding ItemArray[0]}" TextColor="Blue"/>
<Span Text="{Binding ItemArray[1]}" TextColor="Red"/>
<Span Text="{Binding ItemArray[2]}" TextColor="Blue"/>
</FormattedString>
</Label.FormattedText>
When i try to create the label at runtime i get for the Text the "{Binding ItemArray[0]}" and not the actual value
StackLayout ST2 = new StackLayout { Orientation = StackOrientation.Horizontal };
Label LB1 = new Label
{
FormattedText =
new FormattedString
{
Spans =
{
new Span { Text = "{Binding ItemArray[0], Mode=OneWay}", ForegroundColor = Color.Blue },
new Span { Text = "{Binding ItemArray[1], Mode=OneWay}", ForegroundColor = Color.Red },
new Span { Text = "{Binding ItemArray[2], Mode=OneWay}", ForegroundColor = Color.Blue }
}
}
};
ST2.Children.Add(LB1);
use SetBinding
var span = new Span() { ForegroundColor = Color.Blue };
span.SetBinding (Span.TextProperty, "ItemArray[0]");

Google is undefined in infobox.js

I have a Google map html page. It works fine in development under localhost but when I try to put in online, I get Google undefined in the infobox.js file, with this line:
this.extend(InfoBubble, google.maps.OverlayView);
I have the api key loaded and it's called before I load the infobox.js file. I added the callback=initialize to see if it would work, but it doesn't work with it or without it. Here is the code for the html file:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Activities</title>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAVVx45quD8ozW5SJZw-Lk_8QvVsXdWi2Y&sensor=false""></script>
<script type="text/javascript" src="GoogleMaps/Scripts/downloadxml.js"></script>
<script type="text/javascript" src="GoogleMaps/Scripts/infobubble_tabs.js"></script>
<style type="text/css">
html, body { height: 100%; }
.style1
{
width: 758px;
}
.style2
{
width: 349px;
}
#side_bar
{
height: 550px;
width: 349px;
overflow:scroll;
}
</style>
<script type="text/javascript">
//<![CDATA[
// this variable will collect the html which will eventually be placed in the side_bar
var side_bar_html = "";
var gmarkers = [];
var gicons = [];
var map = null;
var InfoBubble = new InfoBubble({
maxWidth: 300
});
//defines icon if there is none stated
gicons["red"] = new google.maps.MarkerImage("http://maps.gstatic.com/mapfiles/ridefinder-images/mm_20_red.png",
new google.maps.Size(20, 34),
new google.maps.Point(0, 0),
new google.maps.Point(9, 9));
// Marker sizes are expressed as a Size of X,Y
// where the origin of the image (0,0) is located
// in the top left of the image.
// Origins, anchor positions and coordinates of the marker
// increase in the X direction to the right and in
// the Y direction down.
var iconImage = new google.maps.MarkerImage('http://maps.gstatic.com/mapfiles/ridefinder-images/mm_20_red.png',
new google.maps.Size(20, 34),
new google.maps.Point(0, 0),
new google.maps.Point(9, 9));
var iconShadow = new google.maps.MarkerImage('http://www.google.com/mapfiles/shadow50.png',
new google.maps.Size(37, 34),
new google.maps.Point(0, 0),
new google.maps.Point(9, 9));
// Shapes define the clickable region of the icon.
// The type defines an HTML <area> element 'poly' which traces out a polygon as a series of X,Y points. The final coordinate closes
//the poly by connecting to the first coordinate.
var iconShape = {
coord: [9, 0, 6, 1, 4, 2, 2, 4, 0, 8, 0, 12, 1, 14, 2, 16, 5, 19, 7, 23, 8, 26, 9, 30, 9, 34, 11, 34, 11, 30, 12, 26, 13, 24, 14, 21, 16, 18, 18, 16, 20, 12, 20, 8, 18, 4, 16, 2, 15, 1, 13, 0],
type: 'poly'
};
//determines icon based on category
//if no icon is defined
function getMarkerImage(iconColor) {
if ((typeof (iconColor) == "undefined") || (iconColor == null)) {
iconColor = "red";
}
if (!gicons[iconColor]) {
gicons[iconColor] = new google.maps.MarkerImage(iconColor,
new google.maps.Size(20, 34),
new google.maps.Point(0, 0),
new google.maps.Point(9, 9));
}
return gicons[iconColor];
}
function category2icon(category) {
var color = "red";
switch (category) {
case "Hike": color = "GoogleMaps/Images/HikingIcon.jpg";
break;
case "KML": color = "GoogleMaps/Images/kml.gif";
break;
case "Camping": color = "GoogleMaps/Images/camping.gif";
break;
case "StatePark": color = "GoogleMaps/Images/statepark.jpg";
break;
case "NationalPark": color = "GoogleMaps/Images/NationalPark_icon.png";
break;
case "PointsofInterest": color = "GoogleMaps/Images/POI.png";
break;
case "CountyPark": color = "GoogleMaps/Images/CountyPark_Icon.png";
break;
case "Biking": color = "GoogleMaps/Images/Bike_icon.jpg";
break;
case "FishWildlifeService": color = "GoogleMaps/Images/FishWildlife_icon.gif";
break;
case "Kayak": color = "GoogleMaps/Images/kayaking.png";
break;
case "Shelter": color = "GoogleMaps/Images/Shelter_Icon.png";
break;
case "Parking": color = "GoogleMaps/Images/Parking_Lot_Icon.png";
break;
default: color = "red";
break;
}
return color;
}
gicons["Hike"] = getMarkerImage(category2icon("Hike"));
gicons["KML"] = getMarkerImage(category2icon("KML"));
gicons["Camping"] = getMarkerImage(category2icon("Camping"));
gicons["StatePark"] = getMarkerImage(category2icon("StatePark"));
gicons["NationalPark"] = getMarkerImage(category2icon("NationalPark"));
gicons["PointsofInterest"] = getMarkerImage(category2icon("PointsofInterest"));
gicons["CountyPark"] = getMarkerImage(category2icon("CountyPark"));
gicons["Biking"] = getMarkerImage(category2icon("Biking"));
gicons["FishWildlifeService"] = getMarkerImage(category2icon("FishWildlifeService"));
gicons["Kayak"] = getMarkerImage(category2icon("Kayak"));
gicons["Shelter"] = getMarkerImage(category2icon("Shelter"));
gicons["Parking"] = getMarkerImage(category2icon("Parking"));
// A function to create the marker and set up the event window
function createMarker(latlng, name, url, detail_tab, notes_tab, map_tab, hiking_detail_tab, camping_detail_tab, category, state) {
var contentString_detail = detail_tab;
var contentString_notes = notes_tab;
var contentString_maps = map_tab;
var contentString_hiking_detail = hiking_detail_tab;
var contentString_camping_detail = camping_detail_tab;
var marker = new google.maps.Marker({
position: latlng,
icon: gicons[category],
shadow: iconShadow,
map: map,
title: name,
zIndex: Math.round(latlng.lat() * -100000) << 5
});
// === Store the category and name info as a marker properties ===
marker.mycategory = category;
marker.mystate = state;
marker.myname = name;
gmarkers.push(marker);
// to open the info bubbles
google.maps.event.addListener(marker, 'click', function () {
InfoBubble.open(map, marker);
InfoBubble.removeTab(4);
InfoBubble.removeTab(3);
InfoBubble.removeTab(2);
InfoBubble.removeTab(1);
InfoBubble.removeTab(0);
if (category == "KML") {
window.open("" + url);
}
if (!category == "KML") {
InfoBubble.addTab('Details', contentString_detail);
}
if (!notes_tab == "") {
InfoBubble.addTab('Notes', contentString_notes);
}
if (!map_tab == "") {
switch (category) {
case "Camping": InfoBubble.addTab('Campsite Map', contentString_maps);
break;
case "Hike": InfoBubble.addTab('Trail Map', contentString_maps);
break;
}
}
if (!hiking_detail_tab == "") {
InfoBubble.addTab('Trail Notes', contentString_hiking_detail);
}
if (!camping_detail_tab == "") {
InfoBubble.addTab('Campsite Notes', contentString_camping_detail);
}
});
}
// == shows all markers of a particular category, and ensures the checkbox is checked ==
function show(category) {
for (var i = 0; i < gmarkers.length; i++) {
if (gmarkers[i].mycategory == category) {
gmarkers[i].setVisible(true);
}
}
// == check the checkbox ==
document.getElementById(category + "box").checked = true;
}
// == hides all markers of a particular category, and ensures the checkbox is cleared ==
function hide(category) {
for (var i = 0; i < gmarkers.length; i++) {
if (gmarkers[i].mycategory == category) {
gmarkers[i].setVisible(false);
}
}
// == clear the checkbox ==
document.getElementById(category + "box").checked = false;
// == close the info window, in case its open on a marker that we just hid
InfoBubble.close();
}
// == a checkbox has been clicked ==
function boxclick(box, category) {
if (box.checked) {
show(category);
} else {
hide(category);
}
// == rebuild the side bar
makeSidebar();
}
function myclick(i) {
google.maps.event.trigger(gmarkers[i], "click");
}
// == rebuilds the sidebar to match the markers currently displayed ==
function makeSidebar() {
var html = "";
for (var i = 0; i < gmarkers.length; i++) {
if (gmarkers[i].getVisible()) {
html += '<a href="javascript:myclick(' + i + ')">' + gmarkers[i].myname + '<\/a><br>';
}
}
document.getElementById("side_bar").innerHTML = html;
}
function initialize() {
var myOptions = {
zoom: 8,
center: new google.maps.LatLng(39.364032, -77.182159),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map"), myOptions);
// Closes any open bubbles before opening new one
google.maps.event.addListener(map, 'click', function () {
InfoBubble.close();
});
//Downloads the data from xml file
// Reads the data the creates each tab
downloadUrl("GoogleMaps/categories.xml", function (doc) {
var xml = xmlParse(doc);
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
// obtain the attribues of each marker
var lat = parseFloat(markers[i].getAttribute("lat"));
var lng = parseFloat(markers[i].getAttribute("lng"));
var point = new google.maps.LatLng(lat, lng);
var address = markers[i].getAttribute("address");
var city = markers[i].getAttribute("city");
var state = markers[i].getAttribute("state");
var zip = markers[i].getAttribute("zip");
var name = markers[i].getAttribute("name");
var notes = markers[i].getAttribute("notes");
var url = markers[i].getAttribute("url");
var hike_distance = markers[i].getAttribute("hike_distance");
var hike_trail_skill_level = markers[i].getAttribute("hike_trail_skill_level");
var hike_points_of_interest = markers[i].getAttribute("hike_points_of_interest");
var Camping_Amenities = markers[i].getAttribute("Camping_Amenities");
var Camping_Best_Sites = markers[i].getAttribute("Camping_Best_Sites");
var Camping_Notes = markers[i].getAttribute("Camping_Notes");
var image = markers[i].getAttribute("image");
var category = markers[i].getAttribute("category");
//Creates data for Detail Tab
var detail_tab = "";
detail_tab += "<b>" + name + "<\/b><p>";
detail_tab += address + "</br>";
detail_tab += city + ", " + state + " " + zip + "</br>";
detail_tab += '<br><a target="_blank" href="' + url + '">' + url + '</a>' + "</br>";
//Creates data for Notes Tab
var notes_tab = notes;
//Creates data for Maps Tab
var map_tab = "";
if (image) {
map_tab += '<br><a target="_blank" href="' + image + '">' + image + '</a>' + "</br>";
}
//Creates data for Hiking Detail Tab
var hiking_detail_tab = "";
if (hike_distance) {
hiking_detail_tab += "<b>Trail Distance: </b>" + hike_distance + " miles</br>";
hiking_detail_tab += "<b>Trail Skill Level: </b>" + hike_trail_skill_level + "</br>";
hiking_detail_tab += "<b>Points of Interest: </b>" + hike_points_of_interest + "</br>";
}
//Creates data for Camping Detail Tab
var camping_detail_tab = "";
if (Camping_Notes) {
camping_detail_tab += "<b>Amenities: </b>" + Camping_Amenities + "</br>";
camping_detail_tab += "<b>Best Sites: </b>" + Camping_Best_Sites + "</br>";
camping_detail_tab += "<b>Notes: </b>" + Camping_Notes + "</br>";
}
// var kml_tab = "";
// if (category=="KML) {
// create the marker
var marker = createMarker(point, name, url, detail_tab, notes_tab, map_tab, hiking_detail_tab, camping_detail_tab, category);
}
// == show or hide the categories initially ==
show("Hike");
show("KML");
hide("Camping");
hide("StatePark");
hide("NationalPark");
hide("PointsofInterest");
hide("CountyPark");
hide("Biking");
hide("FishWildlifeService");
hide("Kayak");
hide("Shelter");
hide("Parking");
// == create the initial sidebar ==
makeSidebar();
});
}
//]]>
</script>
</head>
<body style="margin:0px; padding:0px;" onload="initialize()">
<table border="1" >
<tr>
<td class="style1">
<div id="map" style="width:978px; height: 596px"></div>
</td>
<td valign="top" style="text-decoration: underline; color: #4444ff;"
class="style2">
<h4>To view a topo map, click map in the top left corner and select terrain from drop down menu</h4>
<div id="side_bar"></div>
</td>
</tr>
</table>
<form action="#">
Hiking: <input type="checkbox" id="Hikebox" onclick="boxclick(this,'Hike')" />
Full Trail Map: <input type="checkbox" id="KMLbox" onclick="boxclick(this,'KML')" />
Trail Shelters: <input type="checkbox" id="Shelterbox" onclick="boxclick(this,'Shelter')" />
Trail Parking: <input type="checkbox" id="Parkingbox" onclick="boxclick(this,'Parking')" />
Camping: <input type="checkbox" id="Campingbox" onclick="boxclick(this,'Camping')" />
Biking: <input type="checkbox" id="Bikingbox" onclick="boxclick(this,'Biking')" />
Kayaking: <input type="checkbox" id="Kayakbox" onclick="boxclick(this,'Kayak')" />
<br />
State Parks: <input type="checkbox" id="StateParkbox" onclick="boxclick(this,'StatePark')" />
National Parks: <input type="checkbox" id="NationalParkbox" onclick="boxclick(this,'NationalPark')" />
County Park: <input type="checkbox" id="CountyParkbox" onclick="boxclick(this,'CountyPark')" />
<br />
Points of Interest: <input type="checkbox" id="PointsofInterestbox" onclick="boxclick(this,'PointsofInterest')" />
Fish and Wildlife Service: <input type="checkbox" id="FishWildlifeServicebox" onclick="boxclick(this,'FishWildlifeService')" />
<br />
</form>
<noscript><b>JavaScript must be enabled in order for you to use Google Maps.</b>
However, it seems JavaScript is either disabled or not supported by your browser.
To view Google Maps, enable JavaScript by changing your browser options, and then
try again.
</noscript>
</body>
</html>
Remove the callback-parameter. When you use the callback-parameter the asynchronous version of the maps-API will be loaded.
You can't use the asynchronous version of the API here because infobox.js only works when the maps-API has already been loaded(what may happen with the asynchronous version, but must not).
In this special case the API never will be loaded, because the body-element is still unknown (but it must be available, because the script tries to inject another script-element into the body).
When you say that it also doesn't work without the callback-parameter there must be another issue that will not be exposed by the code, please post more code or a demo/link.

How to detect two simultaneous touches?

Detecting touch in Windows Phone 8 leverages the System.Windows.Input.Touch.FrameReported event which is the most raw and certainly the most responsive touch event available to developers.
You would use the event like this:
public MainPage()
{
InitializeComponent();
// setup sounds
Ellipse1.Tag = new Uri("Sounds/GVD_snr1.wav", UriKind.Relative);
Ellipse2.Tag = new Uri("Sounds/GVD_snr2.wav", UriKind.Relative);
Ellipse3.Tag = new Uri("Sounds/GVD_snr3.wav", UriKind.Relative);
Ellipse4.Tag = new Uri("Sounds/GVD_snr4.wav", UriKind.Relative);
Ellipse5.Tag = new Uri("Sounds/GVD_snr5.wav", UriKind.Relative);
Ellipse6.Tag = new Uri("Sounds/GVD_snr6.wav", UriKind.Relative);
Ellipse7.Tag = new Uri("Sounds/Gong.wav", UriKind.Relative);
// respond to touch(es)
var _Ellipses = new[] { Ellipse1, Ellipse2, Ellipse3, Ellipse4, Ellipse5, Ellipse6, Ellipse7 };
System.Windows.Input.Touch.FrameReported += (s, e) =>
{
var _Touches =
from touch in e.GetTouchPoints(null)
where touch.Action == System.Windows.Input.TouchAction.Down
let ellipse = touch.TouchDevice.DirectlyOver as Ellipse
where _Ellipses.Contains(ellipse)
select ellipse;
System.Diagnostics.Debug.WriteLine("{0} touch(es).", _Touches.Count());
foreach (var ellipse in _Touches)
{
var _Stream = Application.GetResourceStream(ellipse.Tag as Uri).Stream;
var _SoundEffect = Microsoft.Xna.Framework.Audio.SoundEffect.FromStream(_Stream);
Microsoft.Xna.Framework.FrameworkDispatcher.Update();
_SoundEffect.Play();
}
};
}
(tested with a Lumia 920)
This works like a charm - as long as there is only a single touch at a time. When the user attempts to touch two or more points simultaneously (and I mean exactly the same time) the event is not raised at all. When the user attempts to touch two or more points almost simultaneously (just a split second apart) then the event is raised and both points are reported.
How can I detect two simultaneous touches?
In case you want to see the XAML, here's the XAML:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.Resources>
<Style TargetType="Ellipse">
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Top" />
</Style>
</Grid.Resources>
<Ellipse x:Name="Ellipse1" Fill="Blue" Height="177" Margin="17,17,0,0" Width="177"/>
<Ellipse x:Name="Ellipse2" Fill="#FFFFA300" Height="223" Margin="212,25,0,0" Width="223"/>
<Ellipse x:Name="Ellipse3" Fill="#FFFF00E8" Height="97" Margin="89,207,0,0" Width="97"/>
<Ellipse x:Name="Ellipse4" Fill="#FF00C135" Height="162" Margin="186,249,0,0" Width="162"/>
<Ellipse x:Name="Ellipse5" Fill="#FF00AEFF" Height="272" Margin="59,416,0,-81" Width="272"/>
<Ellipse x:Name="Ellipse6" Fill="Red" Height="97" Margin="320,395,0,0" Width="97"/>
<Ellipse x:Name="Ellipse7" Fill="#FFF3FF00" Height="133" Margin="10,304,0,0" Width="133"/>
</Grid>
Adding this resolved the problem:
var _Timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(50) };
_Timer.Tick += (s, e) =>
{
try { Microsoft.Xna.Framework.FrameworkDispatcher.Update(); }
catch { }
};
_Timer.Start();

Get a href from xml file into a flash button

I have a flash file where I'm trying to change the value of the same button depending on the image that is clicked but I can't make it work with different values (I can only make it work with a static value).
AS:
var weblinkXML:XML = new XML();
weblinkXML.ignoreWhite = true;
weblinkXML.load("xml/main.xml");
weblinkXML.onLoad = function(success) {
trace("success = "+success);
for (var i:Number = 0; i< weblinkXML.childNodes.length; i++) {
PPTBUTTON.addEventListener(MouseEvent.CLICK, fl_ClickToGoToWebPage_1);
function fl_ClickToGoToWebPage_1(event:MouseEvent):void
{
navigateToURL(new URLRequest("test/test.html"), "_blank");
}
}
}
my XML:
<?xml version="1.0" encoding="iso-8859-1"?>
<content>
<!-- general vars -->
<settings>
<item name="copyright"><![CDATA[<font letterspacing="0.5">© 2012 | PRIVACY POLICY</font>]]></item>
<item name="companyName"><![CDATA[<font letterspacing="-2"><b>TANITA</b></font>]]></item>
<item name="companySlogan"><![CDATA[<font letterspacing="1">PHOTO PORTFOLIO</font>]]></item>
<!--mp3Url srcUrl="music.mp3"/-->
<imagesPage>
<image imageUrl="images/tfile_splash_pic_main.jpg" />
</imagesPage>
</settings>
<!-- menu -->
<menu>
<button><![CDATA[PORTFOLIO]]></button>
<button><![CDATA[ABOUT]]></button>
<button><![CDATA[NEWS]]></button>
<button><![CDATA[CONTACTS]]></button>
</menu>
<gallery gallName="Crystal Cabin Awards 2012">
<image imageUrl="gallery/tfile_gall_small_01.jpg" imagesBig="gallery/tfile_gall_big_01.jpg" buttonName="PPTBUTTON" targ="_self" href="http://www.google.com"/>
<image imageUrl="gallery/tfile_gall_small_02.jpg" imagesBig="gallery/tfile_gall_big_02.jpg" buttonName="PPTBUTTON" targ="_self" href="http://www.youtube.com"/>
<image imageUrl="gallery/tfile_gall_small_03.jpg" imagesBig="gallery/tfile_gall_big_03.jpg" buttonName="PPTBUTTON" targ="_self" href="http://www.yahoo.com"/>
<image imageUrl="gallery/tfile_gall_small_04.jpg" imagesBig="gallery/tfile_gall_big_04.jpg"/>
<image imageUrl="gallery/tfile_gall_small_05.jpg" imagesBig="gallery/tfile_gall_big_05.jpg"/>
<image imageUrl="gallery/tfile_gall_small_06.jpg" imagesBig="gallery/tfile_gall_big_06.jpg"/>
<image imageUrl="gallery/tfile_gall_small_07.jpg" imagesBig="gallery/tfile_gall_big_07.jpg"/>
<image imageUrl="gallery/tfile_gall_small_08.jpg" imagesBig="gallery/tfile_gall_big_08.jpg"/>
</gallery>
I realize my xml is complex but it's being used through the entire flash. Maybe I could reduce it to a stand alone xml just like:
<image imageUrl="gallery/tfile_gall_small_02.jpg" imagesBig="gallery/tfile_gall_big_02.jpg" buttonName="PPTBUTTON" targ="_self" href="http://www.youtube.com"/>
my issue is that I've tried to get the href into a variable and use it instead of "test/test.html" but it never works.
I also realize I have a method inside a for but at this point I've iterated so much over this code that I'm unsure how to proceed.
Here's how i would retrieve the list of href attributes:
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("xml/main.xml");
loader.addEventListener(IOErrorEvent.IO_ERROR, function errorHandler(event:IOErrorEvent):void {
trace("Error loading XML" + event.type);
});
loader.addEventListener(Event.COMPLETE, function(event:Event):void {
trace("success = " + event);
var xml:XML = new XML(loader.data);
var xmllist:XMLList = xml.gallery.children();
for (var i:Number = 0; i < xmllist.length(); i++) {
trace(XML(xmllist[i]).attribute("href"));
}
});
loader.load(request);
I had the following output:
success = [Event type="complete" bubbles=false cancelable=false eventPhase=2]
http://www.google.com
http://www.youtube.com
http://www.yahoo.com
I hope that helps.

Google Map Integrated with Salesforce is Blank

I followed the example code line by line from:
How do I integrate Salesforce with Google Maps?
I am not receiving any errors but my Map is blank. The map displays the zoom and position toggle but nothing else.
Any ideas on why?
Here is my Controller Code and Page Code Below
public class mapController2 {
public String address {get;set;}
private List<Account> accounts;
public void find() {
// Normal, ugly query.
/* address = 'USA';
String addr = '%' + address + '%';
accounts = [SELECT Id, Name, BillingStreet, BillingCity, BillingCountry FROM Account
//WHERE Name LIKE :addr OR BillingStreet LIKE :addr OR BillingCity LIKE :addr OR BillingCountry LIKE :addr];
WHERE BillingCountry LIKE :addr];*/
// address = 'Austin';
String addr = '*' + address + '*';
// Or maybe a bit better full-text search query.
List<List<SObject>> searchList = [FIND :addr IN ALL FIELDS RETURNING
Account (Id, Name, BillingStreet, BillingCity, BillingState, BillingCountry)];
accounts = (List<Account>)searchList[0];
}
public List<Account> getAccounts() {
return accounts;
}
}
Page Code
<apex:page controller="mapController2" tabStyle="Account">
<head>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<style>
#map {
height:350px;
}
</style>
</head>
<apex:form >
<apex:pageBlock title="Search by Address">
<apex:inputText value="{!address}"/>
<apex:commandButton value="Search" action="{!find}"/>
<p>Examples: "USA", "Singapore", "Uni", "(336) 222-7000".
Any text data (free text, not picklists, checkboxes etc.) will do.
</p>
</apex:pageBlock>
<apex:pageBlock title="Matching Accounts" rendered="{!address != null}">
<apex:pageBlockTable value="{!accounts}" var="account" id="accountTable">
<apex:column >
<apex:facet name="header"><b>Name</b></apex:facet>
<apex:outputLink value="../{!account.Id}">{!account.Name}</apex:outputLink>
</apex:column>
<apex:column >
<apex:facet name="header"><b>Address</b></apex:facet>
{!account.BillingStreet}, {!account.BillingCity}, {!account.BillingCountry}
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:pageBlock title="Map" rendered="{!address != null}">
<div id="log"></div>
<p>Tip: hover mouse over marker to see the Account name. Click to show the baloon.</p>
<div id="map">Placeholder - map will be created here.</div>
<script type="text/javascript">
// First we need to extract Account data (name and address) from HTML into JavaScript variables.
var names = new Array();
var addresses = new Array();
var htmlTable = document.getElementById('j_id0:j_id2:j_id7:accountTable').getElementsByTagName("tbody")[0].getElementsByTagName("tr");
for (var i = 0; i < htmlTable.length; ++i) {
names.push(htmlTable[i].getElementsByTagName("td")[0]);
// We need to sanitize addresses a bit (remove newlines and extra spaces).
var address = htmlTable[i].getElementsByTagName("td")[1].innerHTML;
addresses.push(address.replace(/\n/g, "").replace(/^\s+/,"").replace(/\s+$/,""));
}
var coordinates = new Array(); // Array of latitude/longitude coordinates.
var markers = new Array(); // Red things we pin to the map.
var baloons = new Array(); // Comic-like baloons that can float over markers.
var counter = 0;
var mapOptions = {
zoom: 5,
mapTypeId: google.maps.MapTypeId.ROADMAP,
navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.ZOOM_PAN
}
};
var map = new google.maps.Map(document.getElementById("map"), mapOptions);
if(addresses.length > 0) {
geocodeOneAddress();
}
function geocodeOneAddress(){
var geocoder = new google.maps.Geocoder();
geocoder.geocode({address: addresses[counter]}, processGeocodingResults);
}
function processGeocodingResults(results, status) {
++counter;
if (status == google.maps.GeocoderStatus.OK) {
coordinates.push(results[0].geometry.location);
} else {
logError(addresses[counter] + " could not be found, reason: " + status);
}
if(counter == addresses.length) {
finalizeDrawingMap();
} else {
geocodeOneAddress();
}
}
function finalizeDrawingMap() {
// Compute min/max latitude and longitude so we know where is the best place to center map & zoom.
var minLat = coordinates[0].b;
var maxLat = coordinates[0].b;
var minLong = coordinates[0].c;
var maxLong = coordinates[0].c;
for(i=0;i < coordinates.length; i++){
markers.push(new google.maps.Marker({ position: coordinates[i], map: map, title: names[i].getElementsByTagName("a")[0].innerHTML, zIndex:i}));
baloons.push(new google.maps.InfoWindow({content: '<b>'+names[i].innerHTML + '</b><br/>' + addresses[i]}));
google.maps.event.addListener(markers[i], 'click', function() {
baloons[this.zIndex].open(map,this);
});
minLat = Math.min(minLat, coordinates[i].b);
maxLat = Math.max(maxLat, coordinates[i].b);
minLong = Math.min(minLong, coordinates[i].c);
maxLong = Math.max(maxLong, coordinates[i].c);
}
map.setCenter(new google.maps.LatLng(minLat + (maxLat-minLat) / 2, minLong + (maxLong-minLong) / 2));
// All that is left is to possibly change the zoom. Let us compute the size of our rectangle.
// This is just a rough indication calculation of size of rectangle that covers all addresses.
var size = (maxLat-minLat) * (maxLong-minLong);
var zoom = 13;
if(size > 7100) {
zoom = 2;
}
else if(size > 6000) {
zoom = 3;
}
else if(size > 550) {
zoom = 4;
}
else if(size > 20) {
zoom = 6;
}
else if(size > 0.12) {
zoom = 9;
}
map.setZoom(zoom);
}
function logError(msg) {
var pTag = document.createElement("p");
pTag.innerHTML = msg;
document.getElementById('log').appendChild(pTag);
}
</script>
</apex:pageBlock>
</apex:form>
</apex:page>
Ya even I was getting a blank map but try to do
https://c.na3.visual.force.com/apex/map?id=0015000000UsQZR
Make sure you enter a valid account id to use.
<apex:page standardController="Account">
<script src="http://maps.google.com/maps?file=api">
</script>
<script type="text/javascript">
var map = null;
var geocoder = null;
var address = "{!Account.BillingStreet}, {!Account.BillingPostalCode} {!Account.BillingCity}, {!Account.BillingState}, {!Account.BillingCountry}";
function initialize() {
if(GBrowserIsCompatible())
{
map = new GMap2(document.getElementById("MyMap"));
map.addControl(new GMapTypeControl());
map.addControl(new GLargeMapControl3D());
geocoder = new GClientGeocoder();
geocoder.getLatLng(
address,
function(point) {
if (!point) {
document.getElementById("MyMap").innerHTML = address + " not found";
} else {
map.setCenter(point, 13);
var marker = new GMarker(point);
map.addOverlay(marker);
marker.bindInfoWindowHtml("Account Name : <b><i> {!Account.Name} </i></b>
Address : "+address);
}
}
);
}
}
</script>
<div id="MyMap" style="width:100%;height:300px"></div>
<script>
initialize() ;
</script>
</apex:page>
Hope this helps
Thanks
tosha
And use the code given as:
src="http://maps.google.com/maps/api/js?sensor=false"
Use
https
not
http
It will definately be blank in firefox or chrome if using http and not https. Try https.