List of neearby searched types IOS xcode - ios

So this piece of code gets nearest searchedTypes(atms and banks) for google and puts markers around the map.
private func fetchNearbyPlaces(coordinate: CLLocationCoordinate2D) {
mapView.clear()
dataProvider.fetchPlacesNearCoordinate(coordinate, radius:searchRadius, types: searchedTypes) { places in
places.forEach {
let marker = PlaceMarker(place: $0)
marker.map = self.mapView
}
}
}
How do I get a table view with the list of these nearest searedTypes and get information on them to show on another viewcontroller where I can navigate from user location to that point. How the normal google maps works.

With places acquired, you can pass data to a new controller that has table view and display data there.

Related

Reloading Google Map View when adding and removing markers

We are coding in Swift to create an application with UI buttons. These UI buttons will add or remove markers depending on its status. Because we want the buttons to be layered on top of google maps we have two view controllers. The top view controller contains a button. When the button is pressed, we want to remove the markers that have a "bad" status.
This is our code to remove the marker:
func showOnlyGood(){
mapView.clear() //this is the google map (GMSMapView.map)
for x in arrayOfGood { //Array of good markers
x.map = mapView //Set good markers to show
}
for y in arrayOfBad { //Array of bad markers
y.map = nil //removes markers from map
}
}
The google maps gets updated if the function call is in viewDidLoad(), but when we call the function in the top view controller with the buttons it does not update the map accordingly.
We think this is an issue with refreshing the google map view and have tried many different solutions, but the google map view only shows what is initially in viewDidLoad().
First, if you just want the buttons to be layered on top of the map, just add the buttons to the view after you've added the map to the view; do not create a second view controller. Your problem is most likely caused by this awkward setup. You also don't have an #objc prefix in your action method, which would definitely prevent the button from executing its action.
#objc func updateButtons() {
mapView.clear() // clear the map
for i in someArray {
let marker = GMSMarker()
// configure parameters
marker.map = mapView
}
}
That method will update your map's markers. There is [probably] never a need to refresh the map, even if you want to change styles.

iOS Swift GMSMarker doesn't remove

I'm using google maps and I'm trying to remove a marker.
I'm using the marker.map = nil as the guide says. But the marker remains there..
I can't use map.clear() because I don't want to lose everything...
Any tip?
/// Hide all the markers
func hideMarkers() {
let events = viewModel.events
for event in events {
event.marker?.map = nil
}
}
Official docu https://developers.google.com/maps/documentation/ios-sdk/marker?hl=en
If you wish to make modifications to a marker after you've added it to the map, ensure that you keep hold of the GMSMarker object. You can modify the marker later by making changes to this object.
let marker = GMSMarker(position: position)
marker.map = mapView
marker.map = nil
So you have hold a reference to your marker. I imagine that you're not working on your marker.
A ugly way would be to call a mapView.clear() and re-add all your markers.

How do I allow users to click on iOS maps to show a callout in swift?

I am trying to build an application where I need to show a callout with details regarding business (name, address etc) when user clicks on the points of interests on the map.
I am able to show callout when there is an annotation. But I want to have a functionality similar to apple maps application, where even without an annotation, users are able to directly tap on the point of interest to show the details about that point of interest.
I have already set the following properties on my mapView:
mapView.userInteractionEnabled = true
mapView.showsPointsOfInterest = true
Any help is appreciated.
you can use MKMapViewDelegate and override Mouse Event
override func rightMouseDown(theEvent: NSEvent) {
let eventLocation: NSPoint = theEvent.locationInWindow
// do something
NSNotificationCenter.defaultCenter().postNotification(notification)
}

Fetch the title of map dropped pin via MKPointAnnotation

I need to know how to fetch the title of a dropped pin. I have multiple dropped pins on the map, when the pin is tabbed I want to fetch the title to pass to prepareForSegue. I use this statement "let title = self.pointAnnotation.title" via (MKPointAnnotation) but I get the title of the last dropped pin and not the tabbed pin.
An easy and reliable way to get a reference to the annotation that was tapped is to use the map view's selectedAnnotations array: if let ann = self.mapView.selectedAnnotations[0] as? MKAnnotation {
println("(ann.title!)")
}

Create Map Pins from XML/Array

I'm currently working on a project which grabs a bunch of traffic-cameras from a XML file and and shows them in the app. I have got my Tableview up and running, working perfectly (click on a cell, opens detailView and shows traffic-image). However, I want to display the cameralocations on a map, so users can press the pin they want to see the camera of (and it sends them to a detailView to show the camera).
I'm not sure how to make this work, any ideas?
I got the longitude and latitude coordinates. Link to the XML file: http://webkamera.vegvesen.no/metadata
It is in norwegian but, lengdegrad = longitude and breddegrad = latitude.
This is what I want to achieve (Photoshop screenshot): https://gyazo.com/93d885606efd6e6369018243b64d47e8
I don't know if this is the right place to ask, but please help if you know something :-)
Thanks in advance
To use the XML data:
Add the XML file to your project and use NSXMLParser to read it.
To create annotations on the map:
Create an annotation class based on MKAnnotationView, something like that:
class Annotation: NSObject, MKAnnotation {
var coordinate: CLLocationCoordinate2D
var title: String?
// optionally add subtitle
init(coordinate: CLLocationCoordinate2D, title: String) {
self.coordinate = coordinate
self.title = title
}
}
To create and add the anotations to the map, for each of the parsed items from your XML file create one annotation and add it to the map. Something like this, depending on format of your parsed data. Let's say you have the data in an array called cameras:
for camera in cameras {
let coord = CLLocationCoordinate2DMake(camera.latitude, camera.longitude)
let annotation = Annotation(coordinate: coord, title: camera.title)
mapView.addAnnotation(annotation)
}

Resources