ios - 如何同步移动标记和相机并始终将标记放置在相机位置IOS的中心
<p><p>我希望 GMSMarker 移动到相机。这是我的代码</p>
<pre><code> -(void)addMap {
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:latitude
longitude:longitude
zoom:15];
GMSMapView *mapView = ;
CGRect newFrame = CGRectMake( 0, 0, ,);
mapView = ;
mapView.delegate = self;
mapView.myLocationEnabled = YES;
GMSMarker *marker = [ init];
marker.position = camera.target;
marker.snippet = @"Hello World";
marker.icon = scaledToSize:CGSizeMake(170, 65)];
marker.appearAnimation = kGMSMarkerAnimationPop;
marker.map = mapView;
;
}
</code></pre>
<p>我在 map 上有一个标记,如果用户不滚动 map ,它通常位于 map 的中心。 </p>
<p>当用户滚动 map 时,我希望标记与相机一起移动到新位置,因此它始终位于 map 的中心。</p>
<p><strong>我试试下面的代码</strong> </p>
<pre><code>-(BOOL) mapView:(GMSMapView *) mapView didTapMarker:(GMSMarker *)marker
{
;
return YES;
}
- (void)mapView:(GMSMapView *)mapView didChangeCameraPosition:(GMSCameraPosition *)position
{
marker.position = camera.target;
marker.appearAnimation = kGMSMarkerAnimationPop;
NSLog(@"camera.target.latitude %f,%f",camera.target.latitude,camera.target.longitude);
latitude=camera.target.latitude;
longitude=camera.target.longitude;
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>你可以试试这个:</p>
<pre><code>- (void)mapView:(GMSMapView *)mapView willMove:(BOOL)gesture
{
;
}
- (void)mapView:(GMSMapView *)mapView didChangeCameraPosition:(GMSCameraPosition *)position
{
;
}
- (void)recenterMarkerInMapView:(GMSMapView *)mapView
{
// Get the center of the mapView
CGPoint center = ;
// Reset the marker position so it moves without animation
;
marker.appearAnimation = kGMSMarkerAnimationNone;
marker.position = ;
marker.map = mapView;
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何同步移动标记和相机并始终将标记放置在相机位置IOS的中心,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/31375672/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/31375672/
</a>
</p>
页:
[1]