Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift UI support #73

Open
aliaziada opened this issue Apr 26, 2021 · 2 comments
Open

Swift UI support #73

aliaziada opened this issue Apr 26, 2021 · 2 comments

Comments

@aliaziada
Copy link

aliaziada commented Apr 26, 2021

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
    }
@mouness2020
Copy link

any fix? please help

@mouness2020
Copy link

mouness2020 commented May 4, 2022

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
}

}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants