Googleマップにドラッグアンドドロップ機能を追加しようとしています。全体的には行われますが、1つのことを修正する必要があります。それは私がGMSMarkerをドラッグアンドドロップするとGoogleマップの透過GMSMarkerがまだ存在し、別のGMSMarkerが削除されたときにGMSMarkerが新たに作成したものです。しかし私はGMSMarkerを1つしか必要としません。過去/過去のGMSMarkerを削除する方法どんな提案も素晴らしいでしょう。前もって感謝します。iOS - 複数のGMSMarkerの問題
コード:
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
// Mumbabi address
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:19.01761470
longitude:72.85616440
zoom:4];
// mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapViewGMS.camera=camera;
mapViewGMS.delegate = self;
CLLocationCoordinate2D position = CLLocationCoordinate2DMake([@"19.01761470" floatValue ], [@"72.85616440" floatValue]);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.title = @"This is your current location";
[marker setDraggable: YES];
marker.appearAnimation=0.2f;
marker.map = mapViewGMS;
}
- (void)mapView:(GMSMapView *)mapView didEndDraggingMarker:(GMSMarker *)marker
{
NSLog(@">>> mapView:didEndDraggingMarker: %@", [marker description]);
NSString *lati=[NSString stringWithFormat:@"%f",marker.position.latitude];
NSString *longi=[NSString stringWithFormat:@"%f",marker.position.longitude];
NSString * urpPath = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?latlng=%@,%@&sensor=true",lati,longi];
[[ConnectionManager connectionManagerSharedInstance]sendPOSTRequestForPath:urpPath data:nil timeoutInterval:50 completion:^(NSDictionary *dictionary, NSError *error) {
if(!error){
if(dictionary){
if([dictionary valueForKey:@"results"] == nil || [[dictionary valueForKey:@"status"]isEqualToString:@"ZERO_RESULTS"]){
dispatch_async(dispatch_get_main_queue(), ^{
[self presentViewController:[ViewUtilities showAlert:@"Message!!" :@"Unable to fetch this location, May be this is an invalid loation. However Please Check your Internet Connection, and re- run this app."] animated:YES completion:nil];
});
}
else
{
strUserCurrentAddressAuto=[NSString stringWithFormat:@"%@",[[[dictionary valueForKey:@"results"] objectAtIndex:0] valueForKey:@"formatted_address"]];
NSLog(@"\n\n ***** Great User address found,---> %@ *****\n\n",strUserCurrentAddressAuto);
dispatch_async(dispatch_get_main_queue(), ^{
//[self.automaticallySearchBtn setTitle:self.fullSourceAddress forState:UIControlStateNormal];
UIAlertController *alert= [UIAlertController alertControllerWithTitle:strUserCurrentAddressAuto message:@"Select this Loaction for ?"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *pick = [UIAlertAction actionWithTitle:@"Pick Up Location" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
labelSourceLocation.text=strUserCurrentAddressAuto;
// nil marker title (old title it is : This is your current location)
marker.title = nil;
locationSource = [[CLLocation alloc] initWithLatitude:marker.position.latitude longitude:marker.position.longitude];
if (locationSource !=nil && locationDest!=nil) {
CLLocationDistance dist = [locationSource distanceFromLocation:locationDest]/1000;
NSLog(@"\n\n **** Using Drag and drop Poin, Total distance in K.M. => %f",dist);
totalDistance = [NSString stringWithFormat:@"%f",dist];
}
[alert dismissViewControllerAnimated:YES completion:nil];
}];
UIAlertAction *drop = [UIAlertAction actionWithTitle:@"Drop Location" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
labelDropLocation.text=strUserCurrentAddressAuto;
// nil marker title (old title it is : This is your current location)
marker.title = nil;
locationDest = [[CLLocation alloc] initWithLatitude:marker.position.latitude longitude:marker.position.longitude];
if (locationSource !=nil && locationDest!=nil) {
CLLocationDistance dist = [locationSource distanceFromLocation:locationDest]/1000;
NSLog(@"\n\n **** Using Drag and drop Poin, Total distance in K.M. => %f",dist);
totalDistance = [NSString stringWithFormat:@"%f",dist];
}
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:pick];
[alert addAction:drop];
[self presentViewController:alert animated:YES completion:nil];
});
}
}
}
}];
}
私のフィードバックをご確認ください。 – vaibhav