I'm testing googlemaps using xamarin. Android platforms is ok, but in iOS i cannot see map background. I declared a variable with my credencial in AppDelegate.cs
The test only show pin address. The problem is exclusively with the background (street or satellite)
Test on Android OK.
This object receives all information about the location
readonly Pin _pinCBC = new Pin()
{
Icon = BitmapDescriptorFactory.DefaultMarker(Color.Red),
Type = PinType.Place,
Label = "61CBC",
Address = "Washington Avenue",
Position = new Position(-3.777777, -38.488888),
ZIndex = 1
};
And this method prints the map on screen. Initialize componente and after add object and positioning the pin to center
public MapsPage()
{
InitializeComponent();
map.MyLocationEnabled = true;
map.UiSettings.MyLocationButtonEnabled = true;
_pinCBC.IsDraggable = true;
map.Pins.Add(_pinCBC);
map.SelectedPin = _pinCBC;
map.MoveToRegion(MapSpan.FromCenterAndRadius(_pinCBC.Position, Distance.FromMeters(5000)), true);
}
How could I show background map. Maybe there is any missing property to inform?
iOS Simulator
Related
var _locator = CrossGeolocator.Current;
var mapPosition = await _locator.GetPositionAsync();
var mapSpan = MapSpan.FromCenterAndRadius(
new Xamarin.Forms.Maps.Position(mapPosition.Latitude, mapPosition.Longitude),
Distance.FromMiles(2)
);
Map.MoveToRegion(mapSpan);
Using Xamarin.Forms.Maps.Postion() the correct lat and lon coordinates are calculated.
However, when I add it to MapSpan, the coordinates change to somewhere in the middle of the Atlantic ocean. Not sure what is causing this?
UPDATE:
So the problem is definitely in the Android project. For some reason, GoogleMaps is not recognizing the location passed by the Map Renderer in the shared project. OnMapReady is just using the default lat/lon.
SUCCESS!!!
async Task<Plugin.Geolocator.Abstractions.Position> GetPositionAsync()
{
var _locator = CrossGeolocator.Current;
Plugin.Geolocator.Abstractions.Position myPosition = await _locator.GetPositionAsync();
return myPosition;
}
public void OnMapReady(GoogleMap googleMap)
{
Plugin.Geolocator.Abstractions.Position myPosition = Task.Run(GetPositionAsync).Result;
map = googleMap;
map.MoveCamera(
CameraUpdateFactory.NewLatLng(
new LatLng(myPosition.Latitude, myPosition.Longitude)));
map.AnimateCamera(
CameraUpdateFactory.ZoomTo(10));
The MapSpan properties LatitudeDegree and LongitudeDegrees refer to the degrees of latitude and longitude that are spanned (i.e. the number of degrees of the map that are shown within its view.)
If you are looking for the lat/lng of the center of the map in your span, refer to the Center properties which is a Maps.Postion object.
Re: https://developer.xamarin.com/api/type/Xamarin.Forms.Maps.MapSpan/
Example:
var mapPosition = new Position(38.29, -77.45);
var mapSpan = MapSpan.FromCenterAndRadius(mapPosition, Distance.FromMiles(2));
map.MoveToRegion(mapSpan);
My app's primary tile has live tile capabilities. If however I turn off the live tile functionality, when I return to the Start screen, my app's primary tile is still showing the last state of the live tile.
I was wondering what I need to do in order to restore my app's primary tile to its static state as soon as I turn the live tile functionality off? At the moment, I need to resize the tile or remove/re-insert it to get this effect.
This is the code that runs when I turn off the live tile:
// Remove the Background Agent for the live tile.
ScheduledActionService.Remove("PeriodicTaskForLocation");
// Update tile.
RadFlipTileData extendedData = new RadFlipTileData()
{
WideVisualElement = null,
WideBackVisualElement = null,
IsTransparencySupported = true
};
ShellTile tile = ShellTile.ActiveTiles.First();
if (tile != null)
{
tile.Update(extendedData);
LiveTileHelper.UpdateTile(tile, extendedData);
}
This has done the trick:
// Remove the Background Agent for the live tile.
RemoveAgent("PeriodicTaskForLocation");
// Delete tile.
ShellTile tile = ShellTile.ActiveTiles.First();
if (tile != null)
{
RadFlipTileData extendedData = new RadFlipTileData();
extendedData.IsTransparencySupported = true;
extendedData.WideBackgroundImage = new Uri("/Assets/Tiles/Icon.png", UriKind.Relative);
extendedData.WideBackVisualElement = null;
LiveTileHelper.UpdateTile(tile, extendedData);
}
I am developing a running tracker/pedometer app, I am using geolocator for the same,I am keeping the movement threshold property of the geoLocator to 10 here is my piece of code.
button click event
private void StartButton_Click(object sender, RoutedEventArgs e)
{
myLocator = new Geolocator();
myLocator.DesiredAccuracy = PositionAccuracy.Default;
myLocator.MovementThreshold = 10;
myLocator.ReportInterval=500;
myLocator.PositionChanged += myGeoLocator_PositionChanged;
_startTime = System.Environment.TickCount;
_timer.Start();
}
void myGeoLocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
{
Dispatcher.BeginInvoke(() =>
{
var coord = new GeoCoordinate(args.Position.Coordinate.Latitude, args.Position.Coordinate.Longitude);
if (_line.Path.Count > 0)
{
var previousPoint = _line.Path.Last();
distance += coord.GetDistanceTo(previousPoint);
var millisPerKilometer = (1000.0 / distance) * (System.Environment.TickCount - _previousPositionChangeTick);
_kilometres += Math.Round(distance, 2);
distanceLabel.Text = string.Format("{0:f2} meters", _kilometres);
MessageBox.Show("Changed");
}
else
{
Map.Center = coord;
}
_line.Path.Add(coord);
_previousPositionChangeTick = System.Environment.TickCount;
});
}
The problem is that the position changed event is only getting called once, I am trying to debug the code in emulator by changing the location points but still the event do not get called. where am I doing wrong??
Your code will work on a real device. However, in order to test on the emulator, try by setting the DesiredAccuracy property to High.
From How to test apps that use location data for Windows Phone:
If your app uses the GeoCoordinateWatcher class, you have to specify a value of GeoPositionAccuracy.High in the constructor or in the DesiredAccuracy property of the class before you can test your app with the location sensor simulator. If you leave the accuracy at its default value of GeoPositionAccuracy.Default, the PositionChanged event doesn’t recognize position changes that occur in the location sensor simulator.
There is also another workaround, that consists on running the native Maps app, which seems to fix the problem:
Set a current location in the emulator.
Run your app. It reports the current location as Redmond.
Run the Maps application. It correctly goes to the location set in
step 1.
Run your app again. Now it uses the correct current location.
Source: http://social.msdn.microsoft.com/Forums/wpapps/en-US/c2cc57b1-ba1f-48fb-b285-d6cfbb8f393a/windows-phone-8-emulator-returns-microsofts-location-only
I have a map with 100 pushpins. Every time I tap a pushpin, a textbox with description is opened near that pushpin (only 1 textbox can be opened at a time, when you tap a pushpin, the previous opened textbox is closed first), but sometimes the textbox is not on top of other pushpins, other pushpins appear above the textbox, making it hard to read the description. I've tried using Canvas and Canvas.ZIndex, but nothing worked properly.
I had a similar issue, and I solved it my removing and adding the object again whenever it was tapped.
MapLayer theLayer = new MapLayer();
MapOverlay theOverlay = new MapOverlay()
{
GeoCoordinate = new GeoCoordinate(lat, lng)
};
var pp = new StackPanel { Background = new SolidColorBrush(Colors.Black), Orientation = System.Windows.Controls.Orientation.Vertical };
var img = new Image()
{
Source = new BitmapImage(new Uri(url, UriKind.Absolute)),
Width = 50,
Height = 50
};
pp.Children.Add(img);
img.Tap += (object emitter, System.Windows.Input.GestureEventArgs e) => {
theLayer.Remove(theOverlay);
theLayer.Add(theOverlay);
};
theOverlay.Content = pp;
theLayer.Add(theOverlay);
Hope this helps!
This is my page, which shows the current location of the user:
In the bottom-left of the map control, there is an expand button. On click, the map control should expand to full-screen and the button should change to the collapse button. This would be easy but I want to animate the expand and collapse process. How can I do this?
For an overview of animation properties of XAML elements, look here...
http://windowsphonegeek.com/articles/wp7-animations-in-depthndash-overview-and-getting-started
For a Map, here is some C# code to animate its 'Height' property...
// assumes Map element is called 'map'
double height = map.Height;
double from, to;
// animate from 150 to 800, or vice versa
if (height == 150)
{
from = 150;
to = 800;
}
else
{
from = 800;
to = 150;
}
Storyboard sb = new Storyboard();
DoubleAnimation fillHeightAnimation = new DoubleAnimation();
fillHeightAnimation.From = from;
fillHeightAnimation.To = to;
fillHeightAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.3));
Storyboard.SetTarget(fillHeightAnimation, map);
Storyboard.SetTargetProperty(fillHeightAnimation, new PropertyPath("Height"));
sb.Children.Add(fillHeightAnimation);
sb.Begin();