Search Results

Search found 271 results on 11 pages for 'mapview'.

Page 5/11 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11  | Next Page >

  • Zoom to fit region for all annotations - ending up zooming in between annotations

    - by Krismutt
    Hey everybody!! I have a problem with fitting all my annotations to the screen... sometimes it shows all annotations, but some other times the app is zooming in between the two annotations so that none of them are visible... I want the app to always fit the region to the annotations and not to zoom in between them... what do I do wrong? if ([mapView.annotations count] == 2) { CLLocationCoordinate2D SouthWest = location; CLLocationCoordinate2D NorthEast = savedPosition; NorthEast.latitude = MAX(NorthEast.latitude, savedPosition.latitude); NorthEast.longitude = MAX(NorthEast.longitude, savedPosition.longitude); SouthWest.latitude = MIN(SouthWest.latitude, location.latitude); SouthWest.longitude = MIN(SouthWest.longitude, location.longitude); CLLocation *locSouthWest = [[CLLocation alloc] initWithLatitude:SouthWest.latitude longitude:SouthWest.longitude]; CLLocation *locNorthEast = [[CLLocation alloc] initWithLatitude:NorthEast.latitude longitude:NorthEast.longitude]; CLLocationDistance meter = [locSouthWest distanceFromLocation:locNorthEast]; MKCoordinateRegion region; region.span.latitudeDelta = meter / 111319.5; region.span.longitudeDelta = 0.0; region.center.latitude = (SouthWest.latitude + NorthEast.latitude) / 2.0; region.center.longitude = (SouthWest.longitude + NorthEast.longitude) / 2.0; region = [mapView regionThatFits:region]; [mapView setRegion:region animated:YES]; [locSouthWest release]; [locNorthEast release]; } Any ideas? NEW CODE (by Satya) -(void)zoomToFitMapAnnotations:(MKMapView*)mapview{ if([mapview.annotations count] == 0) return; CLLocationCoordinate2D topLeftCoord; topLeftCoord.latitude = -90; topLeftCoord.longitude = 180; CLLocationCoordinate2D bottomRightCoord; bottomRightCoord.latitude = 90; bottomRightCoord.longitude = -180; for(FSMapAnnotation* annotation in mapView.annotations) { topLeftCoord.longitude = fmin(topLeftCoord.longitude, location.longitude); topLeftCoord.latitude = fmax(topLeftCoord.latitude, location.latitude); bottomRightCoord.longitude = fmax(bottomRightCoord.longitude, savedPosition.longitude); bottomRightCoord.latitude = fmin(bottomRightCoord.latitude, savedPosition.latitude); } MKCoordinateRegion region; region.center.latitude = topLeftCoord.latitude - (topLeftCoord.latitude - bottomRightCoord.latitude) * 0.5; region.center.longitude = topLeftCoord.longitude + (bottomRightCoord.longitude - topLeftCoord.longitude) * 0.5; region.span.latitudeDelta = fabs(topLeftCoord.latitude - bottomRightCoord.latitude) * 1.1; // Add a little extra space on the sides region.span.longitudeDelta = fabs(bottomRightCoord.longitude - topLeftCoord.longitude) * 1.1; // Add a little extra space on the sides region = [mapView regionThatFits:region]; [mapView setRegion:region animated:YES]; } Can't get it to work... FSMapAnnoation is undeclared... how do I fix this?

    Read the article

  • android hellomap example giving exception

    - by avin
    06-14 22:13:33.992: ERROR/AndroidRuntime(331): Uncaught handler: thread main exiting due to uncaught exception 06-14 22:13:34.031: ERROR/AndroidRuntime(331): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.HelloMap}: android.view.InflateException: Binary XML file line #6: Error inflating class com.google.android.maps.MapView 06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496) 06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512) 06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.app.ActivityThread.access$2200(ActivityThread.java:119) 06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863) 06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.os.Handler.dispatchMessage(Handler.java:99) 06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.os.Looper.loop(Looper.java:123) 06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.app.ActivityThread.main(ActivityThread.java:4363) 06-14 22:13:34.031: ERROR/AndroidRuntime(331): at java.lang.reflect.Method.invokeNative(Native Method) 06-14 22:13:34.031: ERROR/AndroidRuntime(331): at java.lang.reflect.Method.invoke(Method.java:521) 06-14 22:13:34.031: ERROR/AndroidRuntime(331): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 06-14 22:13:34.031: ERROR/AndroidRuntime(331): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 06-14 22:13:34.031: ERROR/AndroidRuntime(331): at dalvik.system.NativeStart.main(Native Method) 06-14 22:13:34.031: ERROR/AndroidRuntime(331): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class com.google.android.maps.MapView 06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.view.LayoutInflater.createView(LayoutInflater.java:513) 06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565) 06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618) 06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.view.LayoutInflater.inflate(LayoutInflater.java:407) 06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.view.LayoutInflater.inflate(LayoutInflater.java:276) 06-14 22:13:34.031: ERROR/AndroidRuntime(331): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198) 06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.app.Activity.setContentView(Activity.java:1622) 06-14 22:13:34.031: ERROR/AndroidRuntime(331): at com.example.HelloMap.onCreate(HelloMap.java:16) 06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459) 06-14 22:13:34.031: ERROR/AndroidRuntime(331): ... 11 more 06-14 22:13:34.031: ERROR/AndroidRuntime(331): Caused by: java.lang.reflect.InvocationTargetException 06-14 22:13:34.031: ERROR/AndroidRuntime(331): at com.google.android.maps.MapView.(MapView.java:237) 06-14 22:13:34.031: ERROR/AndroidRuntime(331): at java.lang.reflect.Constructor.constructNative(Native Method) 06-14 22:13:34.031: ERROR/AndroidRuntime(331): at java.lang.reflect.Constructor.newInstance(Constructor.java:446) 06-14 22:13:34.031: ERROR/AndroidRuntime(331): at android.view.LayoutInflater.createView(LayoutInflater.java:500) 06-14 22:13:34.031: ERROR/AndroidRuntime(331): ... 21 more 06-14 22:13:34.031: ERROR/AndroidRuntime(331): Caused by: java.lang.IllegalArgumentException: MapViews can only be created inside instances of MapActivity. 06-14 22:13:34.031: ERROR/AndroidRuntime(331): at com.google.android.maps.MapView.(MapView.java:281) 06-14 22:13:34.031: ERROR/AndroidRuntime(331): at com.google.android.maps.MapView.(MapView.java:254) 06-14 22:13:34.031: ERROR/AndroidRuntime(331): ... 25 more i had done all configuration plz let ny1 got idea?

    Read the article

  • Android Maps Back Button

    - by aaronr
    I'm developing an application that shows a path on a map, determined by a KML file. Specifically, in the MapActivity that is starting the map: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); MapView mapView = (MapView) findViewById(R.id.mapview); mapView.setBuiltInZoomControls(true); Uri uri = Uri.parse("geo:0,0?q=http://urltokml"); Intent mapIntent = new Intent(Intent.ACTION_VIEW, uri); mapIntent.setData(uri); startActivity(Intent.createChooser(mapIntent, kmlFile)); finish(); } The map loads fine and after a few seconds the path described by the KML shows up. The problem is, when I press the "Back" button, it does not return to the previous screen but instead just hides the KML overlay. If the "Back" button is pressed again, it will return to the previous screen. Any ideas of how to solve this?

    Read the article

  • iPhone current user location coordinates showing as (0,0)

    - by ennuikiller
    I'm trying to get the users current latitude and longitude with this viewDidLoad method. The resulting map is correctly indicating the current location however the NSLog consistently shows: 2009-09-19 16:45:29.765 Mapper[671:207] user latitude = 0.000000 2009-09-19 16:45:29.772 Mapper[671:207] user longitude = 0.000000 Anyone know what I am missing here? Thanks in advance for your help! - (void)viewDidLoad { [super viewDidLoad]; [mapView setMapType:MKMapTypeStandard]; [mapView setZoomEnabled:YES]; [mapView setScrollEnabled:YES]; [mapView setShowsUserLocation:YES]; CLLocation *userLoc = mapView.userLocation.location; CLLocationCoordinate2D userCoordinate = userLoc.coordinate; NSLog(@"user latitude = %f",userCoordinate.latitude); NSLog(@"user longitude = %f",userCoordinate.longitude); }

    Read the article

  • Why MKMapView region is different than requested?

    - by Kamil
    Greetings! I'm saving map region into user defaults when my iPhone app is closing like this: MKCoordinateRegion region = mapView.region; [[NSUserDefaults standardUserDefaults] setDouble:region.center.latitude forKey:@"map.location.center.latitude"]; [[NSUserDefaults standardUserDefaults] setDouble:region.center.longitude forKey:@"map.location.center.longitude"]; [[NSUserDefaults standardUserDefaults] setDouble:region.span.latitudeDelta forKey:@"map.location.span.latitude"]; [[NSUserDefaults standardUserDefaults] setDouble:region.span.longitudeDelta forKey:@"map.location.span.longitude"]; When app launches again, i read those values back the same way, so that the user can see exactly the same map view as it was last time: MKCoordinateRegion region; region.center.latitude = [[NSUserDefaults standardUserDefaults] doubleForKey:@"map.location.center.latitude"]; region.center.longitude = [[NSUserDefaults standardUserDefaults] doubleForKey:@"map.location.center.longitude"]; region.span.latitudeDelta = [[NSUserDefaults standardUserDefaults] doubleForKey:@"map.location.span.latitude"]; region.span.longitudeDelta = [[NSUserDefaults standardUserDefaults] doubleForKey:@"map.location.span.longitude"]; NSLog([NSString stringWithFormat:@"Region read : %f %f %f %f", region.center.latitude, region.center.longitude, region.span.latitudeDelta, region.span.longitudeDelta]); [mapView setRegion:region]; NSLog([NSString stringWithFormat:@"Region on map: %f %f %f %f", mapView.region.center.latitude, mapView.region.center.longitude, mapView.region.span.latitudeDelta, mapView.region.span.longitudeDelta]); The region I read from user defaults is (not surprisingly) exactly the same as when it was saved. Notice that what is saved comes directly from the map, so it's not transformed in any way. I set it back on map with setRegion: method, but then it is different! Example results: Region read : 50.241110 8.891555 0.035683 0.042915 Region on map: 50.241057 8.891544 0.050499 0.054932 Does anybody know why this happens?

    Read the article

  • Android maps out of memory error

    - by SamB09
    Hi , sometimes when running a google maps program with an overlay image i will receive a bit map out of memory error. It always seems to be at a random point in the app. Im not sure how to solve this. Anyone have any ideas ? My overlay code is below , im not sure if you need to see the class its called in though? public class MyOverlay2 extends Overlay { private static final double MAX_TAP_DISTANCE_KM = 3; // Rough approximation - one degree = 50 nautical miles private static final double MAX_TAP_DISTANCE_DEGREES = MAX_TAP_DISTANCE_KM * 0.5399568 * 50; private final GeoPoint gPoint; private final Context cont; private final int draw; // private final int lat; public MyOverlay2(Context cont, GeoPoint gPoint1, int draw) { // constructor will be called in the userLocation class to draw an overly image this.cont = cont; this.gPoint = gPoint1; this.draw = draw; } @Override public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { // constructor takes 3 arguments super.draw(canvas, mapView, shadow); // Convert geo coordinates to screen pixels Point screenPoint = new Point(); mapView.getProjection().toPixels(gPoint, screenPoint); //Read the image from the xml resource using a bitmap factory BitmapFactory.Options options=new BitmapFactory.Options(); options.inSampleSize = 1; Bitmap preview_bitmap=BitmapFactory.decodeResource(cont.getResources(),R.drawable.monday12,options); //draw the image at the location specified by the co-ordinates canvas.drawBitmap(preview_bitmap, screenPoint.x - preview_bitmap.getWidth() /2, screenPoint.y - preview_bitmap.getHeight()/2 , null); // get the images height and width values divided by two draw the image at the specified screen points return true; } @Override public boolean onTap(GeoPoint s, MapView mapView) { // Handle tapping on the overlay here return true; } }

    Read the article

  • Crash on replacing map annotations

    - by Alwin
    Solved it, see below code I'm trying to replace annotations on my MapView depending on the distance between user location and annotation. The annotations are getting replaced like they should, but when I touch te mapview my app crashes. This is de code I have so far: NSMutableArray *tempArray = [[NSMutableArray alloc] init]; for (id object in self.mapAnnotations) { if([object isKindOfClass:[ClosedAnnotation class]]) { ClosedAnnotation *ann = (ClosedAnnotation *)object; CLLocation *tempLocation = [[CLLocation alloc] initWithLatitude:ann.coordinate.latitude longitude:ann.coordinate.longitude]; double distance = [self.currentLocation getDistanceFrom: tempLocation] / 1000; [tempLocation release]; if(distance <= 1.0){ [mapView removeAnnotation:object]; OpenAnnotation *openAnnotation = [[OpenAnnotation alloc] initWithLatitude:ann.coordinate.latitude longitude:ann.coordinate.longitude imageSrc:[ann getImageSrcForAnnotation] title:ann.title tekst:[ann getTextForAnnotation] imageSize:[ann getSizeForImage] username:[ann getUserNameForAnnotation] usertext:[ann getUserTextForAnnotation]]; [mapView addAnnotation:openAnnotation]; [tempArray addObject:openAnnotation]; [openAnnotation release]; } else { [tempArray addObject:object]; } } else if([object isKindOfClass:[OpenAnnotation class]]){ OpenAnnotation *ann = (OpenAnnotation *)object; CLLocation *tempLocation = [[[CLLocation alloc] initWithLatitude:ann.coordinate.latitude longitude:ann.coordinate.longitude] autorelease]; double distance = [self.currentLocation getDistanceFrom: tempLocation] / 1000; [tempLocation release]; if(distance > 1.0){ [mapView removeAnnotation:object]; ClosedAnnotation *closedAnnotation = [[ClosedAnnotation alloc] initWithLatitude:ann.coordinate.latitude longitude:ann.coordinate.longitude imageSrc:[ann getImageSrcForAnnotation] title:ann.title tekst:[ann getTextForAnnotation] imageSize:[ann getSizeForImage] username:[ann getUserNameForAnnotation] usertext:[ann getUserTextForAnnotation]]; [mapView addAnnotation:closedAnnotation]; [tempArray addObject:closedAnnotation]; [closedAnnotation release]; } else { [tempArray addObject:object]; } } } [self.mapAnnotations removeAllObjects]; [self.mapAnnotations addObjectsFromArray:tempArray]; [tempArray release]; I solved it by getting rid of the complete "two-class"-structure and handling everything within one annotation class. Works like a charm now.

    Read the article

  • MKAnnotationView for userLocation pin iPhone

    - by Mauricio Galindo
    I have an application that uses MKMapView and at some point in the app I need to remove all the current pins in the map using [mapView removeAnnotations:mapView.annotations] And then I want to show again the current user location mapView.showUserLocation = YES But I can only make it reappear as a regular pin, because the userLocation view class its not public so I cant return views of that type. Here is my code - (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation MKPinAnnotationView* annView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"currentloc"]; if (!annView) { MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"]; annView.pinColor = MKPinAnnotationColorRed; annView.animatesDrop=TRUE; annView.canShowCallout = YES; annView.calloutOffset = CGPointMake(-5, 5); if ([annotation isKindOfClass:[DraggableAnnotationAM class]] ) annView.draggable = YES; return annView; } else { if ([annotation isKindOfClass:[DraggableAnnotationAM class]] ) annView.draggable = YES; annView.annotation = annotation; return annView; } Also I have found through reflection that MKUserLocationView is the class that is used to display the current location, but because its not public its not safe to use and my app keeps crashing and Im sure theres a easier way. Is it possible to do what I want, or should I just never remove the user location annotation of the mapView? Thanks in advance

    Read the article

  • Objective C map view delegate viewForAnnotation for MKAnnotation gets just called after click

    - by user1185486
    I have a simple Map view. It has a method -(void)loadAndDisplayPois{ NSLog(@"loadAndDisplayPois"); if(mapView.annotations.count > 0) [mapView removeAnnotations:mapView.annotations]; self.pois = [self loadPoisFromDatabase]; NSLog(@"self.pois.count: %i", self.pois.count); [mapView addAnnotations:self.pois]; NSLog(@"mapView.annotations.count: %i",mapView.annotations.count);} This method gets called, and I am sure that the method gets called because of the Log, after I downloaded data and saved it into the database. The class which handles the download executes after saving the data to the database [self.senderObj performSelector:@selector(loadAndDisplayPois)]; Where senderObj is the MapViewControlller. The count Log from the pois array shows 4 after the first time I clicked. But no Annotations on the view, because viewForAnnotation is not called (one Annotation in the array ( my current position)). After I execute the method again by clicking a TEST button shows everything on the map. The viewForAnnotation method gets called after viewWillAppear and after I clicked the TEST button. It is driving me nuts since 2 days. I cant anymore ...

    Read the article

  • Linking Mapkit with Core Data, Search and user location. Converting annotations from a database in a tableview with search to display in a mapview?

    - by Jon
    Xcode is quite new to me so explanations are appreciated. I am looking to build an application that displays annotations in a mapview (zoomed in on current user location). I want the applications to come from some sort of database rather than manually inputting all the annotations (which is what I'm currently doing) What would be my application type? tab based? window based? i want a tab for a tableview with a list of my annotations and a mapview tab that will show my database of annotations but with the map zoomed in on current location. In a perfect world, it would be great if the user could add favourites from these annotations and keep them in a favourites tableview tab. I'm desperate to work this out and create a fully functional app for a final uni project. i have a working application already but it's nothing like what i am trying to achieve, any help would be much appreciated!!!! Jon (if looked through countless tutorials and as of yet found nothing i can understand to achieve a project like this. Some would call me too ambitious, I just want to make a decent app)

    Read the article

  • Displaying Longitude and Latitude values stored in a SQLite db as a Route on a MapView in Android (N

    - by LordSnoutimus
    I am currently in the process of creating an application that records current location of a mobile device in intervals, displaying the route as a coloured line on the device in real-time. At the same time the application is storing the longitude and latitude in a SQLite database as I want the user to be able to bring up that specific route again. The route has a primary key and each waypoint is linked to that route by a foreign key. What would be the easiest way to display the saved route on the map?.

    Read the article

  • Scaling MKMapView Annotations relative to the zoom level

    - by Jonathan
    The Problem I'm trying to create a visual radius circle around a annonation, that remains at a fixed size in real terms. Eg. So If i set the radius to 100m, as you zoom out of the Map view the radius circle gets progressively smaller. I've been able to achieve the scaling, however the radius rect/circle seems to "Jitter" away from the Pin Placemark as the user manipulates the view. The Manifestation Here is a video of the behaviour. The Implementation The annotations are added to the Mapview in the usual fashion, and i've used the delegate method on my UIViewController Subclass (MapViewController) to see when the region changes. -(void)mapView:(MKMapView *)pMapView regionDidChangeAnimated:(BOOL)animated{ //Get the map view MKCoordinateRegion region; CGRect rect; //Scale the annotations for( id<MKAnnotation> annotation in [[self mapView] annotations] ){ if( [annotation isKindOfClass: [Location class]] && [annotation conformsToProtocol:@protocol(MKAnnotation)] ){ //Approximately 200 m radius region.span.latitudeDelta = 0.002f; region.span.longitudeDelta = 0.002f; region.center = [annotation coordinate]; rect = [[self mapView] convertRegion:foo toRectToView: self.mapView]; if( [[[self mapView] viewForAnnotation: annotation] respondsToSelector:@selector(setRadiusFrame:)] ){ [[[self mapView] viewForAnnotation: annotation] setRadiusFrame:rect]; } } } The Annotation object (LocationAnnotationView)is a subclass of the MKAnnotationView and it's setRadiusFrame looks like this -(void) setRadiusFrame:(CGRect) rect{ CGPoint centerPoint; //Invert centerPoint.x = (rect.size.width/2) * -1; centerPoint.y = 0 + 55 + ((rect.size.height/2) * -1); rect.origin = centerPoint; [self.radiusView setFrame:rect]; } And finally the radiusView object is a subclass of a UIView, that overrides the drawRect method to draw the translucent circles. setFrame is also over ridden in this UIView subclass, but it only serves to call [UIView setNeedsDisplay] in addition to [UIView setFrame:] to ensure that the view is redrawn after the frame has been updated. The radiusView object's (CircleView) drawRect method looks like this -(void) drawRect:(CGRect)rect{ //NSLog(@"[CircleView drawRect]"); [self setBackgroundColor:[UIColor clearColor]]; //Declarations CGContextRef context; CGMutablePathRef path; //Assignments context = UIGraphicsGetCurrentContext(); path = CGPathCreateMutable(); //Alter the rect so the circle isn't cliped //Calculate the biggest size circle if( rect.size.height > rect.size.width ){ rect.size.height = rect.size.width; } else if( rect.size.height < rect.size.width ){ rect.size.width = rect.size.height; } rect.size.height -= 4; rect.size.width -= 4; rect.origin.x += 2; rect.origin.y += 2; //Create paths CGPathAddEllipseInRect(path, NULL, rect ); //Create colors [[self areaColor] setFill]; CGContextAddPath( context, path); CGContextFillPath( context ); [[self borderColor] setStroke]; CGContextSetLineWidth( context, 2.0f ); CGContextSetLineCap(context, kCGLineCapSquare); CGContextAddPath(context, path ); CGContextStrokePath( context ); CGPathRelease( path ); //CGContextRestoreGState( context ); } Thanks for bearing with me, any help is appreciated. Jonathan

    Read the article

  • iPhone mapKit annotation for Current Location

    - by Simon
    Hello Im currently strugglung with annotations. how can i prevent the AnnotationLable for the blue GPS-point. (Here is an Image) - (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(MKAnnotation *) annotation{ if (annotation == mapView.userLocation) { return nil; } the function above isnt working, and i realized that i can't compare two coordinates. Any hint is welcome. Simon

    Read the article

  • MapKit/Location Manager crashes app when unloading view

    - by AppGolfer
    I has a bug where my application crashed "EXC_BAD_ACCESS" when I hit the back key on my navigation bar and the view unloaded that had a MapKit (mapView) and used the Location Manager. Tried for days to fix the bug and finally came up with a fix for anyone that comes across this problem: Add this code to your dealloc (void)dealloc { mapView.delegate = nil; locationManager.delegate = nil; [mapView release]; [locationManager release];

    Read the article

  • Zoom on userLocation

    - by Marco
    Hello, how can I zoom the map on my userLocation automatically in my app? I have the following code to zomm in the map but i must zoom on the userLocation and the following code zooms always to africa? MKCoordinateRegion zoomIn = mapView.region; zoomIn.span.latitudeDelta *= 0.2; zoomIn.span.longitudeDelta *= 0.2; zoomIn.center.latitude = mapView.userLocation.location.coordinate.latitude; zoomIn.center.longitude = mapView.userLocation.location.coordinate.longitude; [mapView setRegion:zoomIn animated:YES];

    Read the article

  • how do i add two delegates to a ui element at run time?

    - by Michael Xu
    Hi everyone, im trying to implement some behaviors when a mapview element scrolls... by coding a delegate for the scrollview inside of a mapview. so, right now, i got a pointer to the scroll view used by the map view in my code. however, i wish to set the delegate of this scroll view inside the map view, but the issue is that the mapview already sets up a default delegate for this scroll view inside the map view. can i make my delegate implement all of the messages of the protocol, explicitly sending them to the mapview's default delegate while also implementing my own behaviors? how else can i go about adding my own delegate behavior, to an already existing default delegate....? thanks everyone, michael

    Read the article

  • Switch activity from a AlertDialog button

    - by Fahim Ahmed
    Let's say , I have three classes : MapsActivity , MyItemizedOverlay & GetDirectionActivity . In MyItemizedOverlay , I want to switch to GetDirectionActivity after the positive dialog button is clicked . ActiveDialog is placed under onTap method , so that I can get the GeoPoint. For this , what I've done : In ItemizedOverlay class : @Override public boolean onTap(GeoPoint p, MapView mapView) { // TODO Auto-generated method stub int lat = p.getLatitudeE6(); int lot = p.getLongitudeE6(); AlertDialog.Builder dialog = new AlertDialog.Builder(mContext); dialog.setTitle("Confirmation"); dialog.setMessage("Confirm this as end point ?"); dialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int arg1) { // TODO Auto-generated method stub Intent intent = new Intent(mContext, GetDestination.class); startActivity(intent); } }); dialog.setNegativeButton("No", null); dialog.show(); return true ; } here IDE shows that I have a error in startActivity(intent) line . I've tried that also : In MyItemizedOverlay class : @Override public boolean onTap(GeoPoint p, MapView mapView) { return super.onTap(p, mapView); } In MapsActivity class : GeoPoint point2 = null ; confirmationOverlay.onTap(point2, mapView) ; int latt = point.getLatitudeE6() ; int longt = point.getLongitudeE6(); final int endpointArray [] = {latt , longt}; if(some condition to show the alert dialog after tapping) { AlertDialog.Builder dialog = new AlertDialog.Builder(MapsActivity.this); dialog.setTitle("Confirmation"); dialog.setMessage("Confirm this location as end point ?"); dialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int arg1) { // TODO Auto-generated method stub Intent intent = new Intent(MapsActivity.this,GetDestination.class); intent.putExtra("geopoint" , endpointArray); startActivity(intent); } }); dialog.setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int arg1) { } }); dialog.show(); } For the if statement what sort of condition I can use ? If I set it just like lat0 then the alertdialog appears without tapping on the map. I know this is very silly , but since I am new in both android & java , I hope you guys will consider it. Please help !

    Read the article

  • remove Annotation removes random amount of annotations at a time

    - by skinny123
    I've got this code to erase an annotations (pins) in my mkmapview without erasing my blue dot (userLocation). The problem is that it erasing the pins I've added in seemingly random numbers. when it's called through an IBAction it removes the first 5 then click again it removes the next 3, then the next 2, then the last one. When pressed I need it to remove that latest pin...etc. etc. for (int i = 0; i < [mapView.annotations count]; i++ ) { if ([[mapView.annotations objectAtIndex:i] isKindOfClass:[MyAnnotation class]]) { [mapView removeAnnotation:[mapView.annotations objectAtIndex:i]]; } }

    Read the article

  • How to perform gui operation in doInBackground method?

    - by jM2.me
    My application reads a user selected file which contains addresses and then displays on mapview when done geocoding. To avoid hanging app the importing and geocoding is done in AsyncTask. public class LoadOverlayAsync extends AsyncTask<Uri, Integer, StopsOverlay> { Context context; MapView mapView; Drawable drawable; public LoadOverlayAsync(Context con, MapView mv, Drawable dw) { context = con; mapView = mv; drawable = dw; } protected StopsOverlay doInBackground(Uri... uris) { StringBuilder text = new StringBuilder(); StopsOverlay stopsOverlay = new StopsOverlay(drawable, context); Geocoder geo = new Geocoder(context, Locale.US); try { File file = new File(new URI(uris[0].toString())); BufferedReader br = new BufferedReader(new FileReader(file)); String line; while ((line = br.readLine()) != null) { StopOverlay stopOverlay = null; String[] tempLine = line.split("~"); List<Address> results = geo.getFromLocationName(tempLine[4] + " " + tempLine[5] + " " + tempLine[7] + " " + tempLine[8], 10); if (results.size() > 0) { Toast progressToast = Toast.makeText(context, "More than one yo", 1000); progressToast.show(); } else if (results.size() == 1) { Address addr = results.get(0); GeoPoint mPoint = new GeoPoint((int)(addr.getLatitude() * 1E6), (int)(addr.getLongitude() * 1E6)); stopOverlay = new StopOverlay(mPoint, tempLine); } if (stopOverlay != null) { stopsOverlay.addOverlay(stopOverlay); } //List<Address> results = geo.getFromLocationName(locationName, maxResults) } } catch (URISyntaxException e) { showErrorToast(e.toString()); //e.printStackTrace(); } catch (FileNotFoundException e) { showErrorToast(e.toString()); //e.printStackTrace(); } catch (IOException e) { showErrorToast(e.toString()); //e.printStackTrace(); } return stopsOverlay; } protected void onProgressUpdate(Integer... progress) { Toast progressToast = Toast.makeText(context, "Loaded " + progress.toString(), 1000); progressToast.show(); } protected void onPostExecute(StopsOverlay so) { //mapView.getOverlays().add(so); Toast progressToast = Toast.makeText(context, "Done geocoding", 1000); progressToast.show(); } protected void showErrorToast(String msg) { Toast Newtoast = Toast.makeText(context, msg, 10000); Newtoast.show(); } } But if geocode fails, I want a dialog popup to let user edit the address. That would require calling on gui method while in doInBackground. What would be a good workaround this?

    Read the article

  • how to use method in AsyncTask in android?

    - by J.R.P
    In my application use JASON webservice to get data from Google Navigarion api. I use the Code is below. i got Exception android.os.NetworkOnMainThreadException. how to use AsyncTask? here is my code. Thanks.`public class MainActivity extends MapActivity { MapView mapView ; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); System.out.println("*************1**************1"); setContentView(R.layout.activity_main); System.out.println("*************2**************"); mapView = (MapView) findViewById(R.id.mapv); System.out.println("*************3**************"); Route route = directions(new GeoPoint((int)(26.2*1E6),(int)(50.6*1E6)), new GeoPoint((int)(26.3*1E6),(int)(50.7*1E6))); RouteOverlay routeOverlay = new RouteOverlay(route, Color.BLUE); mapView.getOverlays().add(routeOverlay); mapView.invalidate(); System.out.println("*************4**************"); } @SuppressLint("ParserError") private Route directions(final GeoPoint start, final GeoPoint dest) { //https://developers.google.com/maps/documentation/directions/#JSON <- get api String jsonURL = "http://maps.googleapis.com/maps/api/directions/json?"; final StringBuffer sBuf = new StringBuffer(jsonURL); sBuf.append("origin="); sBuf.append(start.getLatitudeE6()/1E6); sBuf.append(','); sBuf.append(start.getLongitudeE6()/1E6); sBuf.append("&destination="); sBuf.append(dest.getLatitudeE6()/1E6); sBuf.append(','); sBuf.append(dest.getLongitudeE6()/1E6); sBuf.append("&sensor=true&mode=driving"); Parser parser = new GoogleParser(sBuf.toString()); Route r = parser.parse(); System.out.println("********r in thread*****" +r); return r; } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } @Override protected boolean isRouteDisplayed() { // TODO Auto-generated method stub return false; } } `

    Read the article

  • multiple regionDidChangeAnimated calls - what gives?

    - by mvexel
    I have a MKMapView inside a UITableView as a custom cell (don't ask ;) - don't know if it matters really), for which I register a regionDidChangeAnimated delegate method. This method gets called three times when the UITableView is loaded - once with the actual region and then two more times with a region that is way off. In the simulator, I consistently get a region with center (+37.43997405, -97.03125000). On the device, it seems to depend on the location reported by the location manager, which initializes the map view. Why am I getting three regionDidChangeAnimated calls? And why are the center coordinates for the last two of them off? This is the code I use to get the center coordinates: - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated { CLLocation *l = [[CLLocation alloc] initWithLatitude:self.mapView.centerCoordinate.latitude longitude:self.mapView.centerCoordinate.longitude]; (....)

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11  | Next Page >