LocationPicker icon indicating copy to clipboard operation
LocationPicker copied to clipboard

Swift UI support

Open aliaziada opened this issue 3 years ago • 2 comments

Is there any plan to support swift ui i used UIViewControllerRepresentable to integrate picker but search bar won't show

 func makeUIViewController(context: Context) -> LocationPickerViewController {
        let locationPicker = LocationPickerViewController()
        let placemark = MKPlacemark(coordinate: CLLocationCoordinate2D(latitude: initalLat, longitude: initalLong), addressDictionary: nil)
        let location = Location(name: "Current location", location: nil, placemark: placemark)
        locationPicker.location = location
        
        // button placed on right bottom corner
        locationPicker.showCurrentLocationButton = true // default: true
        // default: navigation bar's `barTintColor` or `UIColor.white`
        locationPicker.currentLocationButtonBackground = .red

        // ignored if initial location is given, shows that location instead
        locationPicker.showCurrentLocationInitially = true // default: true

        locationPicker.mapType = .standard // default: .Hybrid

        // for searching, see `MKLocalSearchRequest`'s `region` property
        locationPicker.useCurrentLocationAsHint = true // default: false
        

        locationPicker.searchBarPlaceholder = "Search places" // default: "Search or enter an address"

        locationPicker.searchHistoryLabel = "Previously searched" // default: "Search History"

        // optional region distance to be used for creation region when user selects place from search results
        locationPicker.resultRegionDistance = 500 // default: 600

        locationPicker.completion = completion
        return locationPicker
    }

aliaziada avatar Apr 26 '21 13:04 aliaziada

any fix? please help

mouness2020 avatar May 03 '22 14:05 mouness2020

works fine

`struct LocationPicker: UIViewControllerRepresentable {

func updateUIViewController(_ uiViewController: UINavigationController, context: Context) {
    
}

func makeUIViewController(context: Context) -> UINavigationController {
    let locationPicker = LocationPickerViewController()
    //let placemark = MKPlacemark(coordinate: CLLocationCoordinate2D(latitude: initalLat, longitude: initalLong), addressDictionary: nil)
    // let location = Location(name: "Current location", location: nil, placemark: placemark)
    //locationPicker.location = location
    
    //locationPicker.location = location
    locationPicker.showCurrentLocationButton = true
    locationPicker.useCurrentLocationAsHint = true
    locationPicker.showCurrentLocationInitially = true
    
        
   // locationPicker.completion = {
       // self.location = $0
        
   // }
   
    
    // button placed on right bottom corner
    locationPicker.showCurrentLocationButton = true // default: true
    // default: navigation bar's `barTintColor` or `UIColor.white`
    locationPicker.currentLocationButtonBackground = .red
    
    // ignored if initial location is given, shows that location instead
    locationPicker.showCurrentLocationInitially = true // default: true
    
    locationPicker.mapType = .standard // default: .Hybrid
    
    // for searching, see `MKLocalSearchRequest`'s `region` property
    locationPicker.useCurrentLocationAsHint = true // default: false
    
    
    locationPicker.searchBarPlaceholder = "Search places" // default: "Search or enter an address"
    
    locationPicker.searchHistoryLabel = "Previously searched" // default: "Search History"
    
    // optional region distance to be used for creation region when user selects place from search results
    locationPicker.resultRegionDistance = 500 // default: 600
    
    //locationPicker.completion = completion
    locationPicker.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(MainViewHelper().closeAction))

    let navController = UINavigationController(rootViewController: locationPicker)
    navController.modalPresentationStyle = .formSheet
    return navController
}

} `

mouness2020 avatar May 04 '22 10:05 mouness2020