Git Product home page Git Product logo

locationpicker's Introduction

LocationPicker

LocationPickerViewController is a UIViewController subclass to let users choose locations by searching or selecting on map. It's designed to work as UIImagePickerController.

User can select location either by searching or long pressing on map. In both cases you'll receive CLPlacemark, which contains location coordinates as well as information such as the country, state, city, street address, and POI names.

Installation

Uses Swift 5, use version 1.3.0 for Swift 4.2, 1.0.3 for Swift 3, 0.6.0 for Swift 2.

Carthage

github "almassapargali/LocationPicker"

CocoaPods

pod 'LocationPicker'

Swift Package Manager

Swift Package Manager is a dependency manager built into Xcode. LocationPicker supports SPM from version 1.4.3.

If you are using Xcode 11 or higher, go to File -> Swift Packages -> Add Package Dependency and enter the package repository URL, then follow the instructions.

Screenshots

Map Search Select

Usage

Create a new instance in code (LocationPickerViewController()) or by setting class of UIViewController in Storyboard. Then provide completion block which will be called when user closes view controller.

let locationPicker = LocationPickerViewController()

// you can optionally set initial location
let placemark = MKPlacemark(coordinate: CLLocationCoordinate2D(latitude: 37.331686, longitude: -122.030656), addressDictionary: nil)
let location = Location(name: "1 Infinite Loop, Cupertino", 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 = .blue

// 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 = { location in
    // do some awesome stuff with location
}

navigationController?.pushViewController(locationPicker, animated: true)

License

LocationPicker is available under the MIT license. See the LICENSE file for more info.

locationpicker's People

Contributors

3llomi avatar almassapargali avatar bharatkrishna avatar brandon-salahat-tm avatar djbe avatar higalex avatar oggerschummer avatar valydia avatar weakfl avatar woxtu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

locationpicker's Issues

Publish 1.0.0 to cocoapods

Note that your git tag should also point to a later commit where the podspec also has the correct 1.0.0 version.

Forbid map rotation

Hi!
Thank you for this beautiful framework
How can i forbid map rotation?

mapView.isRotateEnabled = false

Unable to type text in search bar

Hello!

I just added LocationPickerViewController as navigationItem to my navigationController. Everything is fine except I'm unable to type text to search for location in searchBar. I can clean search field. I've checked both controllers' settings - they are equal. Could you tell me what's wrong?

Thanks!

add to cocoapod?

please. thanks, it will make us pick up your changes much easier.

how to get placeMark object ?

I want to selected last selected location from map but I have only address string and coordinates for location constructor, placeMark paramter ? can you please remove it ? or fix to stop crashing

let initialLocation = Location(name: "My home", location: location, placeMark: CLPlaceMark )

Alert displays when selecting two locations in rapid succession

Long tap somewhere, and while the pin is dropping (or at least before the info shows up) , long tap somewhere else.

Expected: First pin is dismissed.
What actually happens: First pin is dismissed, but an alert shows up with the following message: The operation couldn't be completed. (kCLErrorDomain error 10.).

Here's a screenshot of that alert:
screen shot 2017-03-08 at 12 04 32 pm

Not possible to localize "Select" button

The button title for the "select location button" created in LocationPickerViewController.selectLocationButton() uses a hardcoded string. It would make sense to have this text customisable from outside to enable localisation and also using an app specific verb.

tap to change pin location

Hi sir,
would it possible to add option so that on tap to change the current location?
currently long tap will do it, but most of user might don't know this.
Because this is location picker, so this option would be very helpful i think.
(i test android lib https://github.com/SchibstedSpain/Leku, which does this)

thanks :)

Current Location

I want to add a button to get current location in completion handler. How it can be done.

Missing argument for parameter 'placemark' in call

The sample posted no longer compiles with xCode 8.1 and Swift 3.

The problem lies on the line:
let initialLocation = Location(name: "my home", location: location)

"Missing argument for parameter 'placemark' in call". The compiler wants:
let initialLocation = Location(name: "my home", location: location, placemark: placemark)

I've been trying to understand how to init CLPlacemark from CLLocation, but I've had no luck.

I can not get xCode to recognize init(location: CLLocation, name: String?, postalAddress: CNPostalAddress?) so I do not have an easy way to create a CLPlacemark from CLLocation.

If I pass in an empty CLPlacemark, it crashes.

Close button

Hi If I open this control as Presented there is no button to close window. How I could add one?

Swift 4

@almassapargali so are you going to update the project to swift 4. Can you let me know. You messaged us telling the community that you were working on it. Is this a broken framework.

select the current location initialy

How can I select the current location when initialy after opening the map, because currently it only shows the current location and the user may think it is already selected or even when the user tap the current location circle it does nothing and the user still has to tap long to select the locatoin

Pod not installing

Hello, I am trying to integrate the pod file in my app and it is taking forever.
Please take a look at my pod file.

use_frameworks!
target 'UberDemo6' do
pod 'UberRides'
pod 'LocationPicker'
end

Localizing searchBarPlaceholder

changing searchBarPlaceholder is changing its value but not the searchbar placeholder value
i think this fix it

LocationPickerViewController
/// default: "Search or enter an address"
public var searchBarPlaceholder : String = "Search or enter an address" {
didSet{
searchBar.placeholder = self.searchBarPlaceholder
}
}

modally present this LocationPicker

Thanks for a great and useful component.
In my case, I have to be able to show this component any where independent of any navigation sequence. So being able to show it modally is important. However this component seems to be designed to work with UINavigationController.

So here is how currently do it.

 @objc func openLocationPicker() {
        
        // setup the location picker
        let locationPicker = LocationPickerViewController()
         
        // add cancel button to dismiss it
        locationPicker.navigationItem.leftBarButtonItem =
            UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(closeLocationPicker))
        
        // set the wrapper
        let nc = UINavigationController(rootViewController: locationPicker)
        
        // show it modally
        UIApplication.shared
            .topViewController()?
            .present(nc, animated: true, completion: {})
    }
    
    // dismiss the modally presented LocationPicker
    @objc func closeLocationPicker() {
        UIApplication.shared
            .topViewController()?
            .presentedViewController?.dismiss(animated: true, completion: nil)
    }

Hope this can be useful for others who got in situation like this.
Thanks!

Annotationview text scaling

Hi,

I'm trying to localize the text used in the AnnotationView. I saw you updated the view a few days ago and now we can set the selectButtonTitle of the AnnotationView. Is there a way to make the AnnotationView larger when the selectButtonTitle text is larger than normal? For instance Select is in Dutch Selecteer which doesn't fit right now in the AnnotationView.

Thx!

Version 1.3.0 not available on cocoapods

Version 1.3.0 does not propagate to cocoapods, see last release.

Did you pod lib lint the latest version? Maybe it fails because the .swift-version still says 3.0?
Whatever the reason is, the update is not available...

current location not working

selectCurrentLocationInitially is set true but when i tapped on right bottom icon for current location , there is no marker and map is not updating for current location

here is my code
let locationPicker = LocationPickerViewController()

    locationPicker.location = location
    locationPicker.searchBarStyle = .prominent
    locationPicker.mapType = .standard
    locationPicker.showCurrentLocationButton = true
    locationPicker.useCurrentLocationAsHint = true
    locationPicker.selectCurrentLocationInitially = true
   
    locationPicker.completion = { location in
        self.lat = location?.coordinate.latitude ?? 0.0
        self.long = location?.coordinate.longitude ?? 0.0
        self.txtaddress.text = location?.address ?? "--"
    }
    navigationController?.pushViewController(locationPicker, animated: true)

Swift 3 ?

Any plan to update library to Swift 3 ?

xcode 8.0 swift convert error

hello guys, recently I opened a project in xcode 8.0 and the swift conversion error came, i selected the swift 3.0 and then this error came, please see the attached image for errors, xcode 7.3.1 produces he same error.

screen shot 2016-09-29 at 1 11 00 pm

Select "Current Location"

Hi @almassapargali , thanks for the great plugin!

I am wondering if it is possible to add the "Select" button for "Current Location" annotation? Currently when tapping on the blue circle of current location, it shows the annotation but not the Select button.

Any way I can enable it or add it in?

Thanks!

Memory issue

When closing controller it's not release from memory

Undefined behavior error for UISearchController

In my project I have a Table View Controller embedded in a Navigation Controller. I am launching the LocationPickerViewController via a button in the navigation bar.
Sometimes when I don't select any location and go back to the previous screen and again come to the Location Picker scene the following error is printed to the console:

Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior (<UISearchController: 0x14a851f90>)

Searching the web, I found this stackoverflow answer which recommended to call the loadViewIfNeeded() method of the UISearchController in the class' deinit.
I added it as follows in LocationPickerViewController:

    deinit {
        searchTimer?.invalidate()
        localSearch?.cancel()
        geocoder.cancelGeocode()
        searchController.loadViewIfNeeded() // Added call to loadViewIfNeeded() 
    }

The error does not appear anymore after this. Maybe this call to loadViewIfNeeded() needs to be added.

Ask for permissions if needed

This picker is idea for apps that don't use location and maps too much, therefore dealing with location permissions would be ideal. At least for my use case.

I could implement it and send a pull request in the following few days if this sounds like something important.

This can be a configurable feature, like locationPicker.askForPermission, and can take three values .No, .WhenInUse, .Always, so the app developers can choose what level of permission to ask for, just in case they use location in different parts of the app.

What do you think?

Select current location

Hi,

Nice work with this picker.
However, I use it in Obj-C project and I want the user to be able to select the current location.
If I press on the standard locate button, the location is not selectable.

How can I do it in your code, using swift? The pin should be added on the current user location.

Thanks.

APIs deprecated for iOS 9

xCode throws method deprecation warnings when Deployment Target is set to 9.2

LocationPicker/LocationPicker/Location.swift:30:12: 'ABCreateStringWithAddressDictionary' was deprecated in iOS 9.0: Use CNPostalAddressFormatter from Contacts.framework instead

LocationPicker/LocationPicker/LocationPickerViewController.swift:325:7: 'pinColor' was deprecated in iOS 9.0: Use pinTintColor instead

inheritance issue

Please, change public type of the class into open class.
I would mix this library with the other but I have to change this restriction properties manually.
For cocoapods this is not a good solution.

Localization question

Hi there, very nice tool.

Is it possible to localize all aspects of this location picker? This would include not only the searchBarPlaceholder and the searchHistoryLabel, but also the Back button, the Cancel button, the Select button and the language of the addresses?

Thank you

Can't install pod

After doing pod install I am greeted with this error

Analyzing dependencies
[!] Unable to find a specification for LocationPicker

location bounds

Hello all!
Thanks for amazing LocationPicker, this library helped me a lot!
I am curious if there's possibility to set latitude / longitude bounds (like Android's LatLngBounds)
for ViewController (northeast and southwest coordinates I guess)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.