2013-04-04 2 views
20

Je suis nouveau sur le développement iOS. Cela concerne la fenêtre d'information Marker dans le SDK Google Maps iOS. Je comprends, nous pouvons créer un marqueur avec une fenêtre d'information en utilisant GMSMarkerOption.Comment afficher une fenêtre d'informations dans iOS Google Maps sans appuyer sur Marker?

GMSMarkerOption *myLocationOption = [GMSMarkerOption alloc]; 
myLocationOption .title = @"My Location"; 
myLocationOption .snippet = @"Lat:...., Lang:...."; 

[mapView addMarkerOption:myLocationOption]; 

Selon le code ci-dessus, Marqueur affiché dans la vue Carte comme prévu. Et en tapant sur le marqueur affiche la fenêtre d'information "Ma position" dans Google Maps, ce qui est bon.

Y at-il de toute façon que nous puissions afficher la fenêtre d'information par programme lorsque l'utilisateur passe à l'écran Carte personnalisée?

Répondre

26
GMSMarkerOptions *myLocationOptions = [GMSMarkerOptions options]; 
myLocationOptions.title = @"My Location"; 
myLocationOptions.snippet = @"Lat:...., Lang:...."; 

mapView.selectedMarker = [mapView addMarkerWithOptions:myLocationOptions]; 

(notez que ses options, et non en option)

+0

gmsmarkeroptions? est-il déprécié? –

55

Cela a changé sur Google Maps SDK et il est plus facile à comprendre:

GMSMarker *marker = [[GMSMarker alloc] init]; 
marker.position = coordinate; 
marker.title = @"Location selected"; 
marker.snippet = @"Testing"; 
marker.map = mapView_; 

//Show info window on map 
[mapView_ setSelectedMarker:marker]; 

Vous utilisez maintenant setSelectedMarker méthode pour afficher une fenêtre d'information d'un marqueur

+0

J'ai utilisé le code ci-dessus mais l'infowindow n'affiche que lorsque je suis appuyé sur le marqueur. Y at-il de toute façon à montrer infowindow et pin simultanément? –

+0

@BandishDave, le code ci-dessus devrait faire ce que vous cherchez. Sinon, peut-être que quelque chose a encore changé sur le SDK – estemendoza

+0

@BandishDave - ** setSelectedMarker ** fonctionne toujours à partir du 26/12/14 (SDK v1.9.1). –

2
// Below line will shows the infowindow for marker with out tapping on it 
    [mapView setSelectedMarker:myLocationOptions]; // myLocationOptions is your desired GMSMarker to show Infowindow with out tapping . 

Happy Cod ing :)

+5

Il a déjà été répondu 2 ans avant le vôtre par @estemendoza! – Husam

7

Swift 3,0

func addMarker(_ location:CLLocation){ 
     var locationMarker: GMSMarker! 
     if locationMarker != nil { 
      locationMarker.map = nil 
     } 
     locationMarker = GMSMarker(position: location.coordinate) 
     locationMarker.map = mapView 
     locationMarker.appearAnimation = kGMSMarkerAnimationPop 
     locationMarker.icon = GMSMarker.markerImage(with: UIColor.green) 
     locationMarker.opacity = 0.85 
     locationMarker.isFlat = true 
     locationMarker.snippet = "My Location" 
     mapView.selectedMarker=locationMarker 

    } 

ligne ci-dessous est la réponse

mapView.selectedMarker=locationMarker 
3

rapide 3

self.mapView.selectedMarker = marker

In th e cas de rapide 3, vous pouvez ouvrir le snipet USInt le selectedMarker

Si vous créez le marqueur d'une manière similaire à:

marker.position = CLLocationCoordinate2D(latitude: 34.1331168, longitude: -118.3550723) 
marker.title = "My super place name" 
marker.snippet = "Are you looking a place to play? This is your place! " 
marker.appearAnimation = kGMSMarkerAnimationPop 
marker.map = self.mapView 
Questions connexes