B4A=true Group=Default Group ModulesStructureVersion=1 Type=Activity Version=9.3 @EndOfDesignText@ #Region Activity Attributes #FullScreen: False #IncludeTitle: False #End Region 'Activity module Sub Process_Globals Dim GPS As GPS Dim rp As RuntimePermissions Dim ruta As String Dim skmt As SQL Dim c As Cursor Dim c2 As Cursor Dim c22 As Cursor Dim c3 As Cursor End Sub Sub Globals Private gmap As GoogleMap Private MapFragment1 As MapFragment Dim Latitud As Double = 0 Dim Longitud As Double = 0 Dim Lat2 As Double = 0 Dim Lon2 As Double = 0 Dim p1, p2 As Location Dim Distance As Float Dim boton1 As Button Dim HUE_BLUE As Float Dim HUE_RED As Float Dim HUE_GREEN As Float Private B_AZUL As Button Private B_ROJO As Button Private B_VERDE As Button Private B_TODOS As Button Dim Tienda As String Dim LatitudRu As Double Dim LongitudRU As Double Dim LIST_AZUL As List Dim LIST_ROJO As List Dim LIST_VERDE As List Dim MARK_AZUL As Marker Dim MARK_ROJO As Marker Dim MARK_VERDE As Marker Dim MARK_CEDIS As Marker Dim rojo As String Dim azul As String Dim verde As String Dim todos As String Dim NumSerie As Int Dim OnInfoWindowClickListener1 As OnInfoWindowClickListener Dim GoogleMapEXTRA As GoogleMapsExtras Dim CODIGO As String Private SEMANA As String Dim lista_punta As List Dim lista_punta2 As List End Sub Sub Activity_Create(FirstTime As Boolean) Activity.LoadLayout("MAPA_RUTAS") ' If File.ExternalWritable Then ' ruta = File.DirDefaultExternal ' Else ruta = File.DirInternal ' End If If File.Exists(ruta, "kmt.db") = False Then File.Copy(File.DirAssets, "kmt.db", ruta, "kmt.db") End If skmt.Initialize(ruta,"kmt.db", True) 'GPS Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION) Wait For Activity_PermissionResult (Permission As String, Result As Boolean) If Result Then StartService(Tracker) Log("Start Tracker") If MapFragment1.IsGooglePlayServicesAvailable = False Then ToastMessageShow("Please install Google Play Services.", True) End If Else ToastMessageShow("No permission", True) B4XPages.ShowPage("Principal") End If ' If(FirstTime) Then ' Starter.GPS.Initialize("GPS") ' End If 'Boton velocidad' ' boton1.Initialize(0) ' boton1.Text = 0 &" "&"km/h" ' boton1.TextColor = Colors.Red ' boton1.TextSize = 15 ' Activity.AddView(boton1, 40%x, 5dip, 25%x, 40dip) 'Fin Boton velocidad' 'MARK_CEDIS.IsInitialized MARK_AZUL.IsInitialized MARK_ROJO.IsInitialized MARK_VERDE.IsInitialized LIST_AZUL.Initialize LIST_ROJO.Initialize LIST_VERDE.Initialize verde = 0 azul = 0 rojo = 0 todos = 1 c=skmt.ExecQuery2("select count(*) AS CUANTOS from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("SEMANA")) c.Position =0 SEMANA = c.GetString("CUANTOS") c.Close If SEMANA > 0 Then c=skmt.ExecQuery2("select CAT_VA_VALOR from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("SEMANA")) c.Position =0 SEMANA = c.GetString("CAT_VA_VALOR") c.Close End If End Sub Sub Activity_Resume Starter.rp.Check(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION) Wait For Activity_PermissionResult (Permission As String, Result As Boolean) If Result Then If Starter.GPS.GPSEnabled = False Then ToastMessageShow("Debe Activar el GPS del Equipo.", True) StartActivity(Starter.GPS.LocationSettingsIntent) Else Starter.GPS.Start(0, 0) End If End If lista_punta.Initialize lista_punta2.Initialize LIST_AZUL.Initialize LIST_ROJO.Initialize LIST_VERDE.Initialize verde = 0 azul = 1 rojo = 0 todos = 0 ' DrawPolygon End Sub Sub MapFragment1_Ready Log("ENTRANDO MapFragment1_Ready") gmap = MapFragment1.GetMap gmap.IsInitialized 'todos= 1 'permisos rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION) Wait For Activity_PermissionResult (Permission As String, Result As Boolean) gmap.MyLocationEnabled = Result Dim JavaMapsObject As JavaObject JavaMapsObject = gmap.GetUiSettings JavaMapsObject.RunMethod("setMapToolbarEnabled", Array As Object(True)) '''''''----------------------------MARKER AZUL - POR VISITAR If azul = 1 Or todos = 1 Then c.IsInitialized c=skmt.ExecQuery("select CAT_CL_CODIGO,CAT_CL_NOMBRE,CAT_CL_LAT,CAT_CL_LONG from kmt_info3 where gestion = 0 and CAT_CL_LAT is not null and CAT_CL_LONG is not null and CAT_CL_LAT <> 0 and CAT_CL_LONG <> 0 and CAT_CL_LAT <> ' ' and CAT_CL_LONG <> ' ' and CAT_CL_CODIGO <> 0 and CAT_CL_CODIGO <> 1") ' skmt.Initialize(ruta,"kmt.db", True) Log($"============== Resultados = ${c.RowCount}"$) If c.RowCount > 0 Then For i = 0 To c.RowCount - 1 c.Position = i ' Log($"|${c.GetString("CAT_CL_LONG")}|${c.GetString("CAT_CL_LAT")}|"$) ' Log(i&"|"&c.GetString("CAT_CL_LAT")&"|") LatitudRu = 0 Log(c.GetString("CAT_CL_CODIGO")&" "& c.GetString("CAT_CL_LAT")) If c.GetString("CAT_CL_LAT") <> "" Then LatitudRu = c.GetString("CAT_CL_LAT") LongitudRU = 0 If c.GetString("CAT_CL_LONG") <> "" Then LongitudRU = c.GetString("CAT_CL_LONG") CODIGO=c.GetString("CAT_CL_CODIGO") Tienda= c.GetString("CAT_CL_NOMBRE") MARK_AZUL = gmap.AddMarker2(LatitudRu, LongitudRU, CODIGO, gmap.HUE_BLUE) MARK_AZUL.Snippet = Tienda Next End If c .Close ' Log("4") If MARK_AZUL.IsInitialized Then LIST_AZUL.Add(MARK_AZUL) End If '''''''----------------------------MARKER VERDE - VENTA If verde = 1 Or todos = 1 Then c2.IsInitialized c2=skmt.ExecQuery("select CAT_CL_CODIGO, CAT_CL_NOMBRE,CAT_CL_LONG,CAT_CL_LAT from kmt_info3 where gestion = 2 and CAT_CL_LAT is not null and CAT_CL_LONG is not null and CAT_CL_LAT <> 0 and CAT_CL_LONG <> 0 and CAT_CL_CODIGO <> 0 and CAT_CL_CODIGO <> 1 UNION select CAT_CL_CODIGO, CAT_CL_NOMBRE,CAT_CL_LONG,CAT_CL_LAT from kmt_info32 where gestion = 2 and CAT_CL_LAT is not null and CAT_CL_LONG is not null and CAT_CL_LAT <> 0 and CAT_CL_LONG <> 0 and CAT_CL_CODIGO <> 0 and CAT_CL_CODIGO <> 1") Log($"============== Resultados = ${c2.RowCount}"$) For i = 0 To c2.RowCount -1 c2.Position = i ' Log($"|${c2.GetString("CAT_CL_LONG")}|${c2.GetString("CAT_CL_LAT")}|"$) If IsNumber(c2.GetString("CAT_CL_LONG")) Then LongitudRU = c2.GetString("CAT_CL_LONG") LatitudRu = c2.GetString("CAT_CL_LAT") CODIGO=c2.GetString("CAT_CL_CODIGO") Tienda= c2.GetString("CAT_CL_NOMBRE") MARK_VERDE = gmap.AddMarker2(LatitudRu, LongitudRU, CODIGO,gmap.HUE_GREEN) MARK_VERDE.Snippet = Tienda End If Next Else If verde = 1 Or todos = 1 Then c2.IsInitialized c2=skmt.ExecQuery("select CAT_CL_CODIGO, CAT_CL_NOMBRE,CAT_CL_LONG,CAT_CL_LAT from kmt_info3 where gestion = 2 and CAT_CL_LAT is not null and CAT_CL_LONG is not null and CAT_CL_LAT <> 0 and CAT_CL_LONG <> 0 and CAT_CL_CODIGO <> 0 and CAT_CL_CODIGO <> 1") Log($"============== Resultados = ${c2.RowCount}"$) For i = 0 To c2.RowCount -1 c2.Position = i ' Log($"|${c2.GetString("CAT_CL_LONG")}|${c2.GetString("CAT_CL_LAT")}|"$) LongitudRU = c2.GetString("CAT_CL_LONG") LatitudRu = c2.GetString("CAT_CL_LAT") CODIGO=c2.GetString("CAT_CL_CODIGO") Tienda= c2.GetString("CAT_CL_NOMBRE") MARK_VERDE = gmap.AddMarker2(LatitudRu, LongitudRU, CODIGO,gmap.HUE_GREEN) MARK_VERDE.Snippet = Tienda Next c2 .Close If MARK_VERDE.IsInitialized Then LIST_VERDE.Add(MARK_VERDE) End If End If ' '''''''----------------------------MARKER ROJO - NO VENTA If rojo = 1 Or todos = 1 Then c3.IsInitialized c3=skmt.ExecQuery("select CAT_CL_CODIGO, CAT_CL_NOMBRE,CAT_CL_LONG,CAT_CL_LAT from kmt_info3 where gestion = 3 and CAT_CL_LAT is not null and CAT_CL_LONG is not null and CAT_CL_LAT <> 0 and CAT_CL_LONG <> 0 and CAT_CL_CODIGO <> 0 and CAT_CL_CODIGO <> 1") Log($"============== Resultados = ${c3.RowCount}"$) For i = 0 To c3.RowCount -1 c3.Position = i ' Log($"|${c3.GetString("CAT_CL_LONG")}|${c3.GetString("CAT_CL_LAT")}|"$) LongitudRU = c3.GetDouble("CAT_CL_LONG") LatitudRu = c3.GetDouble("CAT_CL_LAT") CODIGO = c3.GetString("CAT_CL_CODIGO") Tienda= c3.GetString("CAT_CL_NOMBRE") MARK_ROJO = gmap.AddMarker2(LatitudRu, LongitudRU, CODIGO, gmap.HUE_RED) MARK_ROJO.Snippet = Tienda Next Else If rojo = 1 Or todos = 1 Then c3.IsInitialized c3=skmt.ExecQuery("select CAT_CL_CODIGO, CAT_CL_NOMBRE,CAT_CL_LONG,CAT_CL_LAT from kmt_info3 where gestion = 3 and CAT_CL_LAT is not null and CAT_CL_LONG is not null and CAT_CL_LAT <> 0 and CAT_CL_LONG <> 0 and CAT_CL_CODIGO <> 0 and CAT_CL_CODIGO <> 1") Log($"============== Resultados = ${c3.RowCount}"$) For i = 0 To c3.RowCount -1 c3.Position = i ' Log($"|${c3.GetString("CAT_CL_LONG")}|${c3.GetString("CAT_CL_LAT")}|"$) LongitudRU = c3.GetDouble("CAT_CL_LONG") LatitudRu = c3.GetDouble("CAT_CL_LAT") CODIGO = c3.GetString("CAT_CL_CODIGO") Tienda= c3.GetString("CAT_CL_NOMBRE") MARK_ROJO = gmap.AddMarker2(LatitudRu, LongitudRU, CODIGO, gmap.HUE_RED) MARK_ROJO.Snippet = Tienda Next If MARK_ROJO.IsInitialized Then LIST_ROJO.Add(MARK_ROJO) c3.Close End If End If ''------------------------------ ' MARK_CEDIS = gmap.AddMarker3("19.3961802","-99.0784293","CEDIS", LoadBitmap(File.DirAssets, "marker-azul-0.png")) ' If MARK_VERDE.Visible Or MARK_ROJO.Visible Then ' MARK_CEDIS.Remove ' End If Dim aa As CameraPosition aa.Initialize(LatitudRu,LongitudRU,15)''' RECOMENDABLE CAMBIAR A 10 PARA QUE SE VEAN MAS MARCADORES gmap.AnimateCamera(aa) '''''---------------------- ESTO ES PARA LOS CLICK EN LAS VENTANAS D INFORMACION----------- Dim OnInfoWindowClickListener1 As OnInfoWindowClickListener OnInfoWindowClickListener1.Initialize("OnInfoWindowClickListener1") GoogleMapEXTRA.SetOnInfoWindowClickListener(gmap, OnInfoWindowClickListener1) Dim pol As Cursor = Starter.skmt.ExecQuery("SELECT LAT, LONG FROM POLIGONO") If pol.RowCount > 0 Then For poli = 0 To pol.RowCount -1 pol.Position = poli Dim coords As LatLng coords.Initialize(pol.GetString("LAT"), pol.GetString("LONG")) lista_punta.Add(coords) Next ' Dim coords As LatLng ' coords.Initialize(19.534596, -99.148633) ' lista_punta.Add(coords) ' ' Dim coords2 As LatLng ' coords2.Initialize(19.532618, -99.147368) ' lista_punta.Add(coords2) ' ' Dim coords3 As LatLng ' coords3.Initialize(19.530434, -99.143527) ' lista_punta.Add(coords3) ' ' Dim coords4 As LatLng ' coords4.Initialize(19.527077290122044, -99.1408877054847) ' lista_punta.Add(coords4) ' ' Dim coords5 As LatLng ' coords5.Initialize(19.52232469669526, -99.14022251766785) ' lista_punta.Add(coords5) ' ' Dim coords6 As LatLng ' coords6.Initialize(19.52212245552407, -99.14288326892365) ' lista_punta.Add(coords6) ' ' Dim coords7 As LatLng ' coords7.Initialize(19.52414485532313, -99.1441707292143) ' lista_punta.Add(coords7) ' ' Dim coords9 As LatLng ' coords9.Initialize(19.525681862241495, -99.14623066567934) ' lista_punta.Add(coords9) ' ' Dim coords9 As LatLng ' coords9.Initialize(19.52794689841748, -99.14923473969085) ' lista_punta.Add(coords9) ' ' Dim coords10 As LatLng ' coords10.Initialize(19.52950409236695, -99.15127321848439) ' lista_punta.Add(coords10) If lista_punta.Size >= 4 Then DrawPolygon(lista_punta) End If End If End Sub ' ''''-------------------------- PRUEBA CON MARKER _CLICK Sub OnInfoWindowClickListener1_click(Marker1 As Marker) skmt.ExecNonQuery("delete from CUENTAA") skmt.ExecNonQuery2("INSERT INTO CUENTAA VALUES (?) ", Array As Object(Marker1.Title)) Activity.Finish Starter.pre_viejo = Subs.traeTotalClientepreventaparacredito B4XPages.ShowPage("Cliente") End Sub Sub GPS_LocationChanged (Parametro As Location) MARK_CEDIS.IsInitialized ' Dim sp As Int ' sp = Ceil(Parametro.Speed * 3.6) ' boton1.Text = sp &" "&"km/h" ' Latitud = Parametro.Latitude ' Longitud = Parametro.Longitude ' p2.Initialize2(Latitud,Longitud) ' p1.Initialize2(Lat2, Lon2) ' Distance = p1.DistanceTo(p2) ' If Latitud <> 0 And Longitud <> 0 Then ' If Distance > 10 Then ' Lat2 = Latitud ' Lon2 = Longitud ' Dim cp As CameraPosition ' cp.Initialize2(Parametro.Latitude, Parametro.Longitude, gmap.CameraPosition.Zoom, Parametro.Bearing, 0) ' gmap.AnimateCamera(cp) ' End If ' End If End Sub Sub Activity_Pause (UserClosed As Boolean) GPS.Stop End Sub Sub B_TODOS_Click todos =1 verde = 0 azul = 0 rojo = 0 MapFragment1_Ready End Sub Sub B_VERDE_Click verde = 1 azul = 0 rojo = 0 todos = 0 gmap.Clear MapFragment1_Ready End Sub Sub B_ROJO_Click rojo = 1 verde = 0 azul = 0 todos = 0 gmap.Clear MapFragment1_Ready End Sub Sub B_AZUL_Click azul = 1 verde = 0 rojo = 0 todos = 0 gmap.Clear MapFragment1_Ready End Sub 'Sub MapFragment1_LongClick (mPoint As LatLng) ' ' gmap.AddMarker3(mPoint.Latitude,mPoint.Longitude, "MicroArea ",LoadBitmap(File.DirAssets,"marker-amarillo.png") ).InfoWindowShown = True ' ' lista_punta.Add(19.4826598,-99.1507823) ' lista_punta.Add(19.4866943,-99.1466811) ' lista_punta.Add(19.484925, -99.143379) ' lista_punta.Add(19.482510, -99.149406) ' lista_punta2.Add(mPoint) ' ' ' ' If lista_punta2.Size = 6 Then ' DrawPolygon(lista_punta2) ' End If 'End Sub Sub MapFragment1_Click (Point As LatLng) Log(Point.Latitude) Log(Point.Longitude) End Sub Sub DrawPolygon (PointList As List) Dim GoogleMapsExtras1 As GoogleMapsExtras Dim polygonoptions1 As PolygonOptions polygonoptions1.Initialize polygonoptions1.FillColor=Colors.ARGB(100,255,0,0) polygonoptions1.AddPoints(PointList) polygonoptions1.StrokeColor=Colors.DarkGray polygonoptions1.StrokeWidth=1 Dim pg As Polygon = GoogleMapsExtras1.AddPolygon(gmap, polygonoptions1) End Sub Sub PointInPolygon(point As LatLng, polygon As List) As Boolean Dim x As Double = point.Longitude Dim y As Double = point.Latitude Dim inside As Boolean = False For i = 0 To polygon.Size - 1 Dim j As Int = (i + 1) Mod polygon.Size Dim p1_1 As LatLng = polygon.Get(i) Dim p2_1 As LatLng = polygon.Get(j) Dim xi As Double = p1_1.Longitude Dim yi As Double = p1_1.Latitude Dim xj As Double = p2_1.Longitude Dim yj As Double = p2_1.Latitude Dim intersect As Boolean = ((yi > y) <> (yj > y)) And (x < (xj - xi) * (y - yi) / (yj - yi) + xi) If intersect Then inside = Not(inside) End If Next Return inside End Sub Sub MapFragment1_LongClick (mPoint As LatLng) ' Verificar si el punto está dentro del polígono If lista_punta.Size > 0 Then Dim dentro As Boolean = PointInPolygon(mPoint, lista_punta) If dentro Then ToastMessageShow("El punto está DENTRO del polígono", True) Else ToastMessageShow("El punto está FUERA del polígono", True) End If End If ' Agregar marcador y punto a la lista gmap.AddMarker3(mPoint.Latitude, mPoint.Longitude, "MicroArea ", LoadBitmap(File.DirAssets, "marker-amarillo.png")).InfoWindowShown = True lista_punta2.Add(mPoint) If lista_punta2.Size = 6 Then DrawPolygon(lista_punta2) End If End Sub