No pushpin when using MapsTask on WP8 - windows-phone-8

I can't see the pushpin using MapsTask, the map is ok, but no pushpin on the map, anyone knows why? thank you!
if (geo != null)
{
MapsTask mapsTask = new MapsTask();
mapsTask.Center = geo;
mapsTask.ZoomLevel = 15;
mapsTask.Show();
}

you can use mapTask.SearchTerm, the first result will show on the map with the pushpin.
mapsTask has few APIs to do more works.
If you want multiple pushpins or customize for more info,use map control and design it in xaml and .cs file.
here is a good example:
http://www.geekchamp.com/articles/windows-phone-drawing-custom-pushpins-on-the-map-control-what-options-do-we-have
hopes it helps.

ReverseGeocodeQuery query = new ReverseGeocodeQuery();
query.GeoCoordinate = new GeoCoordinate(lat, longitude);
query.QueryCompleted += (s, e) =>
{
if (e.Error != null)
return;
searchTerm = e.Result[0].Information.Address.Street; // task.SearchTerm will contain the result of address
};
Now , you have the search Term , in MapsTask class, just assign
MapsTask task = new MapsTask();
task.SearchTerm = searchTerm;
This should work fine.

Related

Can't load a service for category "ExternalGraphicFactory"

I'm using geotools-18.5, with JavaFx in Inteliji IDE.
When I want to create PointSymbolizer from a svg or png image.
StyleBuilder builder = new StyleBuilder();
ExternalGraphic extGraphic = builder.createExternalGraphic("file:/home/cuongnv/test.svg", "svg");
I build code OK, but when run, I received warning:
WARNING: Can't load a service for category "ExternalGraphicFactory".
Provider org.geotools.renderer.style.ImageGraphicFactory could not be
instantiated.
Can someone help me ?
Here is full code:
private Style createStyleBuilder(){
StyleBuilder builder = new StyleBuilder();
FilterFactory2 ff = builder.getFilterFactory();
// RULE 1
// first rule to draw cities
// define a point symbolizer representing a city
Graphic city = builder.createGraphic();
city.setSize(ff.literal(50));
ExternalGraphic extGraphic = builder.createExternalGraphic("file:/home/cuongnv/Javafx/GeoTool/geotools_fx_tutorial-master/geotools-fx/src/main/resources/images/console.svg", "svg"); // svg
city.addExternalGraphic(extGraphic);
PointSymbolizer pointSymbolizer = builder.createPointSymbolizer(city);
Rule rule1 = builder.createRule(pointSymbolizer);
rule1.setName("rule1");
rule1.getDescription().setTitle("City");
rule1.getDescription().setAbstract("Rule for drawing cities");
Rule rules[] = new Rule[] {rule1};
FeatureTypeStyle featureTypeStyle = builder.createFeatureTypeStyle("Feature", rules);
Style style = builder.createStyle();
style.setName("style");
style.getDescription().setTitle("User Style");
style.getDescription().setAbstract("Definition of Style");
style.featureTypeStyles().add(featureTypeStyle);
return style;
}
TYPE = DataUtilities.createType(
"Dataset",
"geometry:Geometry:srid=4326"
+ ","
+ "name:String,"
+ "id:String"
);
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE);
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
com.vividsolutions.jts.geom.Point point = geometryFactory.createPoint(new Coordinate(x,y));
featureBuilder.add(point);
SimpleFeature feature = featureBuilder.buildFeature(null);
DefaultFeatureCollection featureCollection = new DefaultFeatureCollection("internal", TYPE);
featureCollection.add(feature);
Style style = createStyleBuilder();
Layer layer = new FeatureLayer(featureCollection, style);
layer.setTitle("New Point");
mapContent.layers().add(layer);
You have set the image mime type incorrectly, it should be:
ExternalGraphic extGraphic = builder.createExternalGraphic("file:/stuff/ian/geoserver/data/styles/burg02.svg", "image/svg"); // svg
and all will work.
EDIT
If you are still having issues then try adding this code to the end of the createStyle module and look at the generated SVG, possibly in GeoServer to test it out.
SLDTransformer styleTransform = new SLDTransformer();
StyledLayerDescriptor sld = sf.createStyledLayerDescriptor();
UserLayer layer = sf.createUserLayer();
layer.setLayerFeatureConstraints(new FeatureTypeConstraint[] {null});
sld.addStyledLayer(layer);
layer.addUserStyle(style);
try {
String xml = styleTransform.transform(sld);
System.out.println(xml);
} catch (TransformerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Xamarin Maps Pins Invisible

I have a very strange issue where the map pins do not show up on the map.
I am using Xamarin.Forms.Maps
I am setting up a map with
map = new CustomMap(
MapSpan.FromCenterAndRadius(
new Position(37, -122), Distance.FromMiles(0.3)), this)
{
IsShowingUser = true,
HeightRequest = 100,
WidthRequest = 960,
VerticalOptions = LayoutOptions.FillAndExpand
};
Then I create an absolute layout and add map to it and set the absoluteLayout to be the content
var absoluteLayout = new AbsoluteLayout
{
BackgroundColor = Color.Red.WithLuminosity(0.9),
VerticalOptions = LayoutOptions.FillAndExpand
};
AbsoluteLayout.SetLayoutBounds(map, new Rectangle(0, 0, 1, 1));
AbsoluteLayout.SetLayoutFlags(map, AbsoluteLayoutFlags.All);
absoluteLayout.Children.Add(map);
absoluteLayout.Children.Add(btn);
Content = absoluteLayout;
I also add an initial pin to the map
PinInfo firstInfo = new PinInfo
{
pinId = "1",
Description = "First Description",
};
var pin = new Pin
{
Type = PinType.Place,
Position = position,
Label = "custom pin",
Address = "custom detail info",
BindingContext = firstInfo,
};
pin.Clicked += async (sender, e) =>
{
await DisplayAlert(pin.Label, "The address is: " + pin.Address, "Cancel");
};
map.Pins.Add(pin);
However, in the app I can see the map, but it is not zoomed to the initial area, adding pins does nothing, and I cannot see the initial Pin.
I've been trying to search online for a very long time now, but for some reason have not found anyone with a similar issue...
Any help is very much appreciated.
Depends on where you are placing your Pin. In other words, what is stored position?
Try the following after adding your Pin:
map.MoveToRegion(MapSpan.FromCenterAndRadius(position, Distance.FromMiles(0.3)));

How to Use Xamarin.Forms and GoogleMaps/GeoLocation

I am writing a Xamarin.Forms PCL app, to support iOS and Android OS for my app.
In the root project, I have a view containing a ViewList and a map (from Xamarin.Forms.Maps).
I learnt I have to use CustomRenderer for each platform to add customized behavior. What I am trying to achieve to add a LocationManager/GeoLocation to identify the users position via GPS and show his position with a pin/marker. Additionally to that, I get positions from the root project of several persons which pins must also be shown within the map.
Should I have to use an interface exporting functionality or use an appropriate custom map renderer?
I have no idea to achieve that, the examples at the Xamarin.Forms website and research within Stackoverflow do not give a hint.
Here is some code I have so far (extract):
using System;
using Awesome;
using Xamarin.Forms;
using Xamarin.Forms.Maps;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using Plugin.Geolocator;
using System.Threading.Tasks;
namespace KiLa
{
public class KidsFinder : ContentPage, ITabPage
{
public string TabIcon => FontAwesome.FAMapMarker;
public string SelectedTabIcon => FontAwesome.FAMapMarker;
private Boolean _showKidsList;
private ListView _listView;
public ObservableCollection<KidsViewModel> kidsList = new ObservableCollection<KidsViewModel>();
public KidsFinder ()
{
Title = "KidsFinder";
// Define listView
// Any near/identified kids? Mockup
// TODO: get real data
Boolean kidsPresent = true;
// Initial height of map
double mapHeight = 300.0;
// coordinates of Beuth Hochschule, Haus Gauss
double latitude = 52.543100;
double longitude = 13.351450;
// Show/hide kidsList (listView)
//Boolean showKidsList = false;
_showKidsList = false;
// Define toggleButton
Button toggleButton = new Button();
toggleButton.Text = "Verstecke Liste";
toggleButton.Clicked += new EventHandler(OnClickEvent);
if(kidsPresent == true)
{
toggleButton.IsVisible = true;
mapHeight = 200.0;
_showKidsList = true;
} else
{
toggleButton.IsVisible = false;
mapHeight = 300.0;
_showKidsList = false;
}
// Mockup some kids
Position pos1 = new Position(latitude + 0.002, longitude + 0.002);
Position pos2 = new Position (latitude - 0.002, longitude - 0.002);
kidsList.Add(new KidsViewModel{Name="Tim", ActualPositon=pos1, DistanceToEducator=5.4});
kidsList.Add(new KidsViewModel{Name="Sabine", ActualPositon=pos2, DistanceToEducator=20.4});
_listView = new ListView();
_listView.ItemsSource = kidsList;
//listView.VerticalOptions = LayoutOptions.FillAndExpand;
_listView.ItemTemplate = new DataTemplate (typeof(KidsCustomCell));
_listView.RowHeight = 50;
if (_showKidsList == false) {
_listView.IsVisible = false;
} else {
_listView.IsVisible = true;
}
// Define mapView
var kidsMap = new KidsMap ();
kidsMap.MapType = MapType.Street;
kidsMap.WidthRequest = 960;
kidsMap.HeightRequest = mapHeight;
kidsMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(latitude,longitude), Distance.FromMiles(0.3)));
// Set label of pins with kids names,
foreach (KidsViewModel kvm in kidsList) {
Pin pin = new Pin() {
Label = kvm.Name,
Position = kvm.ActualPositon
};
kidsMap.Pins.Add(pin);
}
You should use GetLocation and declare the permissions necessary to use the LocationServices
[assembly: UsesPermission(Manifest.Permission.AccessFineLocation)]
[assembly: UsesPermission(Manifest.Permission.AccessCoarseLocation)]
This is not strictly necessary for obtaining the GPS coordinates of the device, but this example will attempt to provide a street address for the current location:
[assembly: UsesPermission(Manifest.Permission.Internet)]
Add a method called InitializeLocationManager to activity
void InitializeLocationManager()
{
_locationManager = (LocationManager) GetSystemService(LocationService);
Criteria criteriaForLocationService = new Criteria
{
Accuracy = Accuracy.Fine
};
IList<string> acceptableLocationProviders = _locationManager.GetProviders(criteriaForLocationService, true);
if (acceptableLocationProviders.Any())
{
_locationProvider = acceptableLocationProviders.First();
}
else
{
_locationProvider = string.Empty;
}
Log.Debug(TAG, "Using " + _locationProvider + ".");
}
The LocationManager class will listen for GPS updates from the device and notify the application by way of events. In this example we ask Android for the best location provider that matches a given set of Criteria and provide that provider to LocationManager.
For more details how to get current location using Xamarin Forms, follow this link: https://developer.xamarin.com/recipes/android/os_device_resources/gps/get_current_device_location/

Is it possible to get closest city to my location using nokia maps on WP8?

I can get my current location on wp8. Then I am trying to do a Geocoding with nokia maps based on that location I always get odd results. None of them point to city or something like that
The code I use for getting location:
Geolocator geolocator = new Geolocator();
geolocator.DesiredAccuracyInMeters = 50;
Geoposition position = await geolocator.GetGeopositionAsync(TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(30));
MyCoordinate = new GeoCoordinate(position.Coordinate.Latitude, position.Coordinate.Longitude);
Then GeoCoding:
var geoQuery = new GeocodeQuery();
geoQuery.SearchTerm = "put city result of reverseGeoding for MyCoordinate";
geoQuery.QueryCompleted += geoQuery_QueryCompleted;
geoQuery.GeoCoordinate = geo;
geoQuery.QueryAsync();
Next:
void geoQuery_QueryCompleted(object sender, QueryCompletedEventArgs<IList<MapLocation>> e)
{
if (e.Error == null && e.Result.Count > 0)
{
}
}
e.Result array can containg GeoCoordinates that point to somethere on earth not always close to MyCoordinate.
Is it possible to get closest city to my location using nokia maps on WP8?
You can use the ReverseGeocodeQuery class to obtain and address from geocoordinates:
ReverseGeocodeQuery query = new ReverseGeocodeQuery();
query.GeoCoordinate = myGeoCoordinate;
query.QueryCompleted += query_QueryCompleted;
query.QueryAsync();
You get an object of MapAddress type, which has many properties, including city:
void query_QueryCompleted(object sender, QueryCompletedEventArgs<System.Collections.Generic.IList<MapLocation>> e)
{
if (e.Error != null)
return;
MapAddress address = e.Result[0].Information.Address;
string city = address.City;
}
In order to use this api, you have to specify ID_CAP_MAP capability in the WMAppManifest.xml file.

windows phone 8 Map API GeocodeQuery.SearchTerm not english got nothing

I use GeocodeQuery to look up the coordinates of a search term.
// Get your current position
var myPosition = await new Geolocator().GetGeopositionAsync(TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(10));
// Define search
var geoQuery = new GeocodeQuery();
geoQuery.SearchTerm = "Taipei";
geoQuery.GeoCoordinate = new GeoCoordinate(myPosition.Coordinate.Latitude, myPosition.Coordinate.Longitude);
geoQuery.QueryCompleted += (s, e) => {
if (e.Error == null && e.Result.Count > 0) {
// e.Result will contain a list of coordinates of matched places.
// You can show them on a map control , e.g.
myMap.Center = e.Result[0].GeoCoordinate;
myMap.ZoomLevel = 2;
}
}
geoQuery.QueryAsync();
It works well! I got some location about "Taipei" successfully,
But, when I search "Taipei" in tranditional chinese "台北",
I got nothing in callback function geoQuery.QueryCompleted,
e.Result.Count = 0
How should I handle the GeocodeQuery search in different language??
Thanks for any help!
The geocodequery use the system language to perform search. If you change your phone language to Chinese you should get results.