I am using bing maps for Windows Phone app, On one Button Tap I want to show all the nearby Hospitals to me, I implemented but it not shows the my nearby hospitals.
private void Nearest_Hospital_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
MapsTask mapsTask = new MapsTask();
mapsTask.SearchTerm = "hospital";
mapsTask.ZoomLevel = 2;
mapsTask.Show();
}
I want to send the User's Current Location to this so that app will help the user to find the Hospitals nearby to the user.
You can get the users location using the GeoLocation API in Windows Phone. You can then use these coordinates to set the center value of the MapTask.
This code will return the user's current location, use this as the center value of the MapTask.
Geolocator myGeolocator = new Geolocator();
Geoposition myGeoposition = await myGeolocator.GetGeopositionAsync();
var lat = myGeoposition.Coordinate.Latitude;
var long = myGeoposition.Coordinate.Longitude;
Related
I have same problem like This question but it occurs only for some directions not for all.
MapPB.IsIndeterminate = true;
MapPB.Visibility = Visibility.Visible;
Geopoint destGeopoint = new Geopoint(new BasicGeoposition() { Latitude = Convert.ToDouble(location.Latitude), Longitude = Convert.ToDouble(location.Longitude) });
MapRouteFinderResult routeResult = await MapRouteFinder.GetDrivingRouteAsync(MyGeopoint, destGeopoint, MapRouteOptimization.Distance, MapRouteRestrictions.None);
if (routeResult.Status == MapRouteFinderStatus.Success)
{
// Use the route to initialize a MapRouteView.
MapRouteView viewOfRoute = new MapRouteView(routeResult.Route);
viewOfRoute.RouteColor = App.ApplicationThemeColor;
viewOfRoute.OutlineColor = App.ApplicationThemeColor;
// Add the new MapRouteView to the Routes collection
// of the MapControl.
MapControl1.Routes.Clear();
MapControl1.Routes.Add(viewOfRoute);
// Fit the MapControl to the route.
await MapControl1.TrySetViewBoundsAsync(
routeResult.Route.BoundingBox,
null,
Windows.UI.Xaml.Controls.Maps.MapAnimationKind.None);
}
MapPB.IsIndeterminate = false;
MapPB.Visibility = Visibility.Collapsed;
In above code routeResult.Status is returning InvalidCredentials but only on some points not for all points.
You need to set the Map Service Token before calling the MapRouteFinder.GetDrivingRouteAsync method. Add the following line code before calling this function and be sure to add your Map service token.
MapService.ServiceToken = "Your Maps Service Token";
If you don't add this, the app may work for some coordinates a bit randomly.
I write Xamarin UITest for Android app. In the app uses google map. Help me please, how to click on a marker on the map?
markers are not showing within the tree of views, my guess is that they're drawn on screen within the map framelayout.
given that the marker is at the center of the map, you could tap it using something like this :
(with a map fragment of id "map")
var map = app.Query("map")
var middleX = (map.First().Rect.Width + map.First().Rect.X) / 2
var middleY = (map.First().Rect.Height + map.First().Rect.Y) / 2
app.TapCoordinates(middleX, middleY)
but I think that's all you can do within the map itself.
If you're building the app yourself, I suggest checking out backdoor methods. These are methods that you can build into the app and then call from the test.
There are plenty of examples for Obj-C and Java apps. Here's an example for C# backdoor methods, which you'd put in either your MainActivity or AppDelegate classes: http://danatxamarin.com/2015/05/07/configuring-backdoor-methods-in-c-for-xamarin-test-cloud/
I'd create a backdoor to return whatever data you need about the map, and then use app.Invoke("myNewMethod"); which will return a string (which could be json). This string could contain screen coordinates, which you could then pass to app.TapCoordinates(x, y);.
The short answer is, Google Maps on Android doesn't really expose objects in an automatable way, so the second best option is backdoors.
If you have a custom renderer for android you can simulate a click inside, the main trick is to access markers inside the renderer:
var field = this.GetType().BaseType.GetField("_markers", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
var markers = (List<Marker>)field.GetValue(this);
now for any element in markers as you cannot send a real click you can just simulate it. Pasting the code from my live project:
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == "ExternalClickedPin")
{
if (FormsControl.ExternalClickedPin != null)
{
var pin = Map.Pins.FirstOrDefault(x => x.MarkerId == FormsControl.ExternalClickedPin.MarkerId);
if (pin != null)
{
var field = this.GetType().BaseType.GetField("_markers", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
var hiddenMarkers = (List<Marker>)field.GetValue(this);
var marker = hiddenMarkers.FirstOrDefault(x => x.Id == pin.MarkerId.ToString());
if (marker != null)
{
//simulating click
//1 invoke clicked event
// pin.SendMarkerClick(); // <- if needed for tests
//2 show info on map
marker.ShowInfoWindow(); //just what i was needing
//3 center pin on map
//Map.MoveToRegion(...); <- not here, im calling this from Forms subclassed control
}
}
FormsControl.ExternalClickedPin = null;
}
}
}
When I press the back button to close the bing maps app and go back to the app, bing maps open again and again and again, can't close them. How to resolve this issue ?(I m on Windows phone 8)
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (NavigationContext.QueryString.TryGetValue("itineraire", out itineraire))
{
// You can specify a label and a geocoordinate for the end point.
GeoCoordinate spaceNeedleLocation = App.Sitegeolocalisation;
LabeledMapLocation spaceNeedleLML = new LabeledMapLocation(App.leSite.SiteName, spaceNeedleLocation);
// If you set the geocoordinate parameter to null, the label parameter is used as a search term.
MapsDirectionsTask mapsDirectionsTask = new MapsDirectionsTask();
mapsDirectionsTask.End = spaceNeedleLML;
// If mapsDirectionsTask.Start is not set, the user's current location is used as the start point.
mapsDirectionsTask.Show();
}
else
{
MapsTask mapsTask = new MapsTask();
mapsTask.ZoomLevel = 17;
//Omit the Center property to use the user's current location.
mapsTask.Center = App.Sitegeolocalisation;
mapsTask.Show();
}
}
You can test the property NavigationMode in NavigationEventArgs, if the NavigationMode is Back, just skip the code you have on the OnNavigatedTo method now.
I'm new to windows phone 8 application. Could you please help me how to show a Map with pushpin for the given Latitude and Longitude in windows phone 8.
Thanks
To learn about maps and navigation click here
this is the official document from windows phone dev center. If you are trying to add some UI element to the maps refer this document click here.
This will use a Grid inside a MapOverlay, and works pretty well...
var textGrid = new Grid();
textGrid.ColumnDefinitions.Add(new ColumnDefinition(){Width = GridLength.Auto});
textGrid.Background = new SolidColorBrush(Colors.Black){Opacity = 0.7};
var distText = new TextBlock();
distText.Margin = new Thickness(8,4,8,4);
distText.Text = <your text>;
distText.Foreground = new SolidColorBrush(Colors.White);
textGrid.Children.Add(distText);
var textOverlay = new MapOverlay { Content = textGrid, GeoCoordinate = midwayCoord };
var layer = new MapLayer();
layer.Add(textOverlay);
Map.Layers.Add(layer);
Map.MapElements.Add(line);
I want let user mark their position in our google maps application and then save it to our database, then it can be showed in our google maps application in the next time.
If you want to save the position where the user clicked you can use a "click" listener to get the latitude and longitude of the click with code like this then send it to your server using an Ajax style call where it can be stored in the database.
var clickListener = GEvent.addListener(map,"click",
function (overlay,latlng,overlaylatlng) {
alert(latlng);
});
This code is for v2 of the Google Maps API. Version 3 should have something similar.
An options is to try geolocation first and let the browser pinpoint them. If the browser doesn't support geolocation or an error occurs you can fall back onto them manually adding their position.
var geolocation = null; // holds the latlng object
navigator.geolocation.getCurrentPosition( geolocation_success_init, geolocation_error_init, {enableHighAccuracy: false, timeout: 10000} );
function geolocation_success_init( position ) {
geolocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
initialize_map();
}
function geolocation_error_init( error ){
initialize_map();
}
when you create your map check for geolocation
if ( geolocation ) {
marker = new google.maps.Marker({
position: geolocation,
map:.map,
title: "Your Location"
});
}