1

I have created Custom Marker with InfoWindow by Creating XIB file. But I want to have down arrow on that marker too so that user get to know that for which marker they have clicked.

and i want to move the infoWindow little it UP from the marker ..I have written down the code for that bu it is not moving up.

My code Below

———————-----------

    googleMapView.delegate = self
    var visibleRegion : GMSVisibleRegion =  googleMapView.projection.visibleRegion()
    var bounds = GMSCoordinateBounds(coordinate: visibleRegion.nearLeft, coordinate: visibleRegion.farRight)


    for Prop: Property in properties
    {

        var latStr = Prop.lat as NSString
        var latDbl : Double  = Double(latStr.floatValue)
        var langStr = Prop.lang as NSString
        var langDbl : Double = Double(langStr.floatValue)

        var marker = GMSMarker()


        let initialLocation = CLLocationCoordinate2DMake(latDbl, langDbl)
        let initialDirection = CLLocationDirection()

        let camera = GMSCameraPosition.cameraWithTarget(initialLocation, zoom: 11)

        googleMapView.camera = camera
        marker.position = CLLocationCoordinate2DMake(latDbl,langDbl)
        //println("latitude: \(latDbl)")
        //println("longitude: \(langDbl)")

        marker.appearAnimation = kGMSMarkerAnimationPop
        marker.icon = UIImage(named: "Map_Marker_Green")
        marker.title = Prop.buildingName as String
        marker.snippet = Prop.proCode as String
        marker.infoWindowAnchor = CGPointMake(0.44, 0.45);
        marker.map = googleMapView
        println("Snippet \(marker.snippet)")

    }

Code for the Marker and InfoWindow Tip ———————————————————————————————————

    func mapView(mapView: GMSMapView!, markerInfoWindow marker: GMSMarker!) -> UIView! {

        var infoWindow :CustomInfoWindow = NSBundle.mainBundle().loadNibNamed("PropertyInfoWindow", owner: self.view, options: nil).first! as! CustomInfoWindow

        infoWindow.proCode = marker.snippet
        infoWindow.title.text = marker.title
        infoWindow.title.layer.cornerRadius = 10
        infoWindow.layer.cornerRadius = 10
        infoWindow.frame = CGRectMake(infoWindow.frame.minX,infoWindow.frame.minY-100,infoWindow.frame.width,infoWindow.frame.height)
        return infoWindow
    }



    func mapView(mapView: GMSMapView!, didTapInfoWindowOfMarker marker: GMSMarker!) {
        var prop: Property = returnPropObj(marker.snippet)
        println(prop.buildingName)
        dispatch_async(dispatch_get_main_queue())
        {
            let unitListingController = self.storyboard?.instantiateViewControllerWithIdentifier("UnitListing") as! UnitListingController
            unitListingController.property = prop
            self.showViewController(unitListingController as UIViewController, sender: unitListingController )
        }

    }

Can any one look into this code and give me suggestion if any? Appreciate help!

dhaval shah
  • 4,499
  • 10
  • 29
  • 42

3 Answers3

0

A suggestion for distinguishing which marker the user has selected would be set marker opacity to .5 or something, but when user chooses a marker, call a function that changes marker.opacity = 1; and bring it back to .5 when another marker is selected. As for infowindow, customize it to have a triangle that points to the marker, maybe. Hope this gives you some ideas.

so_jin_ee
  • 802
  • 6
  • 7
  • So_jin_ee, I have changed the marker opacity .. But couldn't manage to give my infoWindow as down arrow... How can i do that? – dhaval shah Jul 08 '15 at 06:15
0
  • You can use markerInfoContent delegate method to return a view which fits inside the default frame

    func mapView(_ mapView: GMSMapView, markerInfoContents marker: GMSMarker) -> UIView? {
        let infoWindow = Bundle.main.loadNibNamed("CustomInfoWindow", owner: self, options: nil)?.first! as! CustomInfoWindow
        infoWindow.updateView(name: marker.title!, details: marker.snippet!, location: "\(marker.position.latitude), \(marker.position.longitude)")
        let view = UIView(frame: CGRect(x: 0, y: 0, width: 129, height: 61))
        view.addSubview(infoWindow)
        return view
    }
    
rajtharan-g
  • 432
  • 5
  • 14
0

you simply do

    //This allows the info window to centre around the location where the marker is
    infoWindow.center = mapView.projection.point(for: location)
    //This moves the infowindow up from the marker
    infoWindow.center.y -= 150 
Assel Kash
  • 111
  • 3
  • 17