Home > Net >  Display store location via map pin in xamarin form
Display store location via map pin in xamarin form

Time:01-11

I want to expound the title. Currently we are making our thesis/project. We have 2 platforms. Web and mobile.

In our web, we have functionality/feature that admin can insert data of store into database, example fields are name of the store, their products and the LOCATION OF that store.

I am assign in our mobile, one of the functionality is map. I have this UI

enter image description here

That red circle is the parameter of our location or limitation or let say NEARBY ME and the PINS assuming those are the store who subscribes in our system, that's my expected output.

This is what I've done in my tab view "map" with map.

my map xaml

<maps:Map  
    x:Name="myMap"
    MapType="Hybrid"
    IsShowingUser="True"
/>

map.xaml.cs

public  MapPage()
{
    InitializeComponent();
    DisplayCurrentLocation();
  // this.AddMarkerInCurrentLocation();
}
public async void DisplayCurrentLocation()
{
    try
    {
        var request = new GeolocationRequest(GeolocationAccuracy.Medium);
        var location = await Geolocation.GetLocationAsync(request);
        if (location != null)
            
        {
           Position p = new Position(location.Latitude, location.Longitude);
          MapSpan mapSpan = MapSpan.FromCenterAndRadius(p, Distance.FromKilometers(.444));
           myMap.MoveToRegion(mapSpan);
       
        }                      
    
    }
    catch(FeatureNotSupportedException fnsEx)
    {

    }
    catch   
        (FeatureNotEnabledException fneEx)
    { 

    }
    catch(Exception ex)
    {

    }
}

Any link's solution that are related to my post, kindly comment it and Im glad to study the article. Thank you in advance.

CodePudding user response:

Display store location via map pin in xamarin form

If you have obtained the location(Latitude, Longitude) of the stores, you can do this:

List<Location_Store> Location_Stores =new List<Location_Store>();

// Add the location of stores to List
Location_Stores.add(...);

foreach (var item in Location_Stores)            
{                
   Pin pin = new Pin                
   {                    
      Label = item.StoreName,                    
      //Address = "The city with a boardwalk",                    
      Type = PinType.Place,                    
      Position = new Position(item.Latitude,item.Longitude)               
   };                
   myMap.Pins.Add(pin);            
}

Location_Store.cs:

public class Location_Store    
  {        
    public string StoreName { get; set; }        
    public double Latitude { get; set; }        
    public double Longitude { get; set; }
    ...    
  }

For more information about how to display location by pin in Xamarin Forms, you can refer to Xamarin.Forms Map Pins.

  • Related