1

我修改了 Xamarin.Forms 的 Fabulous 示例(使用地图,完整的 Elmish):“ https://fsprojects.github.io/Fabulous/Fabulous.XamarinForms/views-maps.html ”。然而,结果和我预想的不一样。地图没有显示,请告知如何解决问题。谢谢你。

// Copyright 2018-2019 Fabulous contributors. See LICENSE.md for license.
namespace SqueakyApp

open System.Diagnostics
open Fabulous
open Fabulous.XamarinForms
open Fabulous.XamarinForms.LiveUpdate
open Fabulous.XamarinForms.MapsExtension
open Xamarin.Forms
open Xamarin.Forms.Maps

module App =
    // Declaration
    type Model =
        { Count : int
          Step : int
          Pressed : bool }

    type Msg =
        | Increment
        | Decrement
        | UserLocation

    // Functions

    // Lifecycle
    let initModel =
        { Count = 0
          Step = 0
          Pressed = false }

    let init() = initModel, Cmd.none

    let update msg model =
        match msg with
        | Increment -> { model with Count = model.Count + model.Step }, Cmd.none
        | Decrement -> { model with Count = model.Count - model.Step }, Cmd.none
        | Reset -> init()

    let view (model : Model) dispatch =

        let paris = Position(48.8566, 2.3522)
        let london = Position(51.5074, -0.1278)
        let calais = Position(50.9513, 1.8587)
        let timbuktu = Position(16.7666, -3.0026)

        let map =
            View.Map
                (hasZoomEnabled = true, hasScrollEnabled = true,
                 pins = [ View.Pin(paris, label = "Paris", pinType = PinType.Place)
                          View.Pin(london, label = "London", pinType = PinType.Place) ],
                 requestedRegion = MapSpan.FromCenterAndRadius(calais, Distance.FromKilometers(300.0)))
        // View
        View.ContentPage(content = map)

    // Note, this declaration is needed if you enable LiveUpdate
    let program = Program.mkProgram init update view

type App() as app =
    inherit Application()

    let runner =
        App.program
        |> Program.withConsoleTrace
        |> XamarinFormsProgram.run app

截屏

在此处输入图像描述

4

1 回答 1

1

从 Timothé Larivière ( https://github.com/TimLariviere/FabulousContacts ) 学习一个例子。

需要在 .iOS 子目录下的“AppDelegate.fs”文件中初始化 FormsMaps。有源文件供参考。

// Copyright 2018 Fabulous contributors. See LICENSE.md for license.
namespace SqueakyApp.iOS

open System
open UIKit
open Foundation
open Xamarin
open Xamarin.Forms
open Xamarin.Forms.Platform.iOS

[<Register ("AppDelegate")>]
type AppDelegate () =
    inherit FormsApplicationDelegate ()

    override this.FinishedLaunching (app, options) =
        Forms.Init()
        FormsMaps.Init() //*** initialization the FormsMaps is required 
        let appcore = new SqueakyApp.App()
        this.LoadApplication (appcore)
        base.FinishedLaunching(app, options)

module Main =
    [<EntryPoint>]
    let main args =
        UIApplication.Main(args, null, "AppDelegate")
        0

在此处输入图像描述

于 2019-11-04T04:31:14.960 回答