Created
December 7, 2017 16:44
-
-
Save brunoportess/de0944c1340d8b5afd1dc9c66e170244 to your computer and use it in GitHub Desktop.
Xamarin Forms Maps - Android Settings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="preferExternal" package="PACKAGE_NAME" android:versionCode="1" android:versionName="1.0"> | |
<uses-sdk android:minSdkVersion="19" /> | |
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> | |
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | |
<uses-permission android:name="android.permission.INTERNET" /> | |
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> | |
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> | |
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /> | |
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" /> | |
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | |
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | |
<application android:label="App_name" android:theme="@style/MainTheme" android:icon="@drawable/icon"> | |
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="API_KEY_DO_GOOGLE_MAPS" /> | |
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> | |
</application> | |
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Android.App; | |
using Android.Content.PM; | |
using Android.OS; | |
using Prism.Unity; | |
using Microsoft.Practices.Unity; | |
namespace Cliente.Droid | |
{ | |
[Activity(Label = "App_Name", Icon = "@drawable/icon", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] | |
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity | |
{ | |
protected override void OnCreate(Bundle bundle) | |
{ | |
TabLayoutResource = Resource.Layout.tabs; | |
ToolbarResource = Resource.Layout.toolbar; | |
base.OnCreate(bundle); | |
global::Xamarin.Forms.Forms.SetFlags("FastRenderers_Experimental"); | |
global::Xamarin.Forms.Forms.Init(this, bundle); | |
Xamarin.FormsMaps.Init(this, bundle); | |
LoadApplication(new App(new AndroidInitializer())); | |
} | |
} | |
public class AndroidInitializer : IPlatformInitializer | |
{ | |
public void RegisterTypes(IUnityContainer container) | |
{ | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Adicionar essa tag no cabecalho da contentPage*/ | |
xmlns:maps="clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps" | |
/* abaixo eu insiro o mapa */ | |
<maps:Map | |
HorizontalOptions="FillAndExpand" | |
HeightRequest="400" | |
x:Name="MyMap" | |
IsShowingUser="False" | |
MapType="Street" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* O metodo abaixo é invocado pelo MessagingCenter para que receba latitude e longitude da VM que vem da minha API*/ | |
private void SetMapa(Empresa obj) | |
{ | |
/* se nao houver latitude/longitude oculto o mapa */ | |
if(obj.Latitude == 0 || obj.Longitude == 0) | |
{ | |
MyMap.IsVisible = false; | |
return; | |
} | |
//gera a posição no mapa | |
var position = new Position(obj.Latitude, obj.Longitude); // Latitude, Longitude | |
// abaixo gera o pin com os dados a serem exibidos quando clica no pin | |
var pin = new Pin | |
{ | |
Type = PinType.Place, | |
Position = position, | |
Label = obj.Nome, | |
Address = obj.Endereco + " - " + obj.Endereco2 | |
}; | |
MyMap.Pins.Add(pin); | |
//a linha abaixo exibe a posicao marcada pela latitude/longitude com uma distancia de 200 mts de zoom | |
MyMap.MoveToRegion(MapSpan.FromCenterAndRadius(position, Distance.FromMeters(200))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment