I want to remove country / state names from MKMapview in iPhone. Means I need only blank map view without any name on it. Is this possible with MKMapview or any other third party maps.
I want to use this functionality with MKMapTypeStandard map type.
Have a look at MKMapViews property mapType MKMapTypeSatellite. Setting this type you will see a map without any names on it. See the docs:
MkMapView Class Reference
Code:
self.map.mapType = MKMapTypeSatellite;
Related
I trying to add annotation pin to Mapview if and only if there is no such same pin already on mapview to avoid having multiple repeat annotations at the same location.
Any one can show me help?
You can use mapView.view(for:) method.
e.g.
if (self.mapView.view(for: annotation) != nil) {
print("pin already on mapview")
}
The approach suggested by #Kosuke Ogawa would work. However it is not a good idea to rely on the UI determine application state.
For eg: You most probably have a list of annotations stored in some sort of data structure in your view controller (I am guessing an Array). This data structure should be the source of truth.
In your case, to determine if a an Annotation is already on the map, check if the Data structure that feeds the mapview contains the annotation and proceed.
I have an application that uses the Mapkit with a plist that contains my custom annotations. This all works fine.
What I next want to do outside of the map is to be able to locate all the custom annotations that are with say a 10 mile radius of my location or a location I select.
I simply want to return the list of annotations that meet that criteria and present them in a list view.
Any ideas what would be the best way of doing this?
If you create CLLocation objects out of your data, which you must be capable of doing if you;re able to get them to your map, you can then compare their distances to the location of your choice using distanceFromLocation
I have to show different types of map views as in the google map there are 2 views.
So I want to know how can we show different map views using mapkitin iphone application?
mapType
The type of data displayed by the map view.
#property(nonatomic) MKMapType mapType
Discussion:
Changing the value in this property may cause the receiver to begin loading new map content. For example, changing from MKMapTypeStandard to MKMapTypeSatellite might cause it to begin loading the satellite imagery needed for the map. If new data is needed, however, it is loaded asynchronously and appropriate messages are sent to the receiver’s delegate indicating the status of the operation.
My question is about the "readonly" attribute of the "coordinate" property. In the Protocol there is also a "setCoordinate" instant method listed. It says in the documentation that it is meant to support "dragging".
My question is :
1
If the coordinate can be set, then why there is a "readonly" attribute assigned to it ?
2
I am thinking of using a single temporary MKAnnotation object to populate an array. The scheme is to assign different coordinate values and add it to the array repeatedly. But the scheme would not work if the coordinate property is "readonly". Or can I use the "setCoordinate" for this purpose anyway ?
Am just wish to avoid having to create multiple MKAnnotation objects to populate the array (since the array can potentially be more that just a few points).
Hope that somebody knowledgable in this area could help ...
http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKAnnotation_Protocol/Reference/Reference.html
The setCoordinate: method is optional. If your annotation supports dragging, you can implement it but you don't have to. The readonly property on the other hand is mandatory.
I am thinking of using a single temporary MKAnnotation object to populate an array. The scheme is to assign different coordinate values and add it to the array repeatedly. But the scheme would not work if the coordinate property is "readonly". Or can I use the "setCoordinate" for this purpose anyway ?
This scheme won't work in any case. If you add the annotation to your array, then modify the coordinate and add it again, you'll have the exact same annotation twice in your array, with the same coordinates. If you want an array of annotations with different coordinates, you will need to create a distinct annotation object for each coordinate.
I am working with an NSMutableArray of objects that conform to the MKAnnotation protocol. My question is over time new objects are added to the array, can anyone tell me what is the preferred method for updating the annotations on the mapView. Should I be looking at removing all the pins before adding back the updated array, or would I be better to mark/tag existing pins in the MKAnnotation object and only add back the new (un-tagged) pins?
Removing all the pins and adding back the whole array including the new annotations will result in flicker and unnecessarily redrawing pins that haven't changed.
Unless the flicker is desired or a full refresh is necessary for some reason, it's better to just tell the map view to add the new pins.
After your main annotation array is updated with the new pins, construct a temporary array called say newAnnots containing references to the new annotations in the main array and pass newAnnots to the map view's addAnnotations: method. The temporary array can be discarded afterwards.
However, instead of using tagging to identify "new" annotations, you could just check if the annotation object in your main array already exists in the map view's annotations array. For example:
if (![mapView.annotations containsObject:annot_from_your_main_array]) {
[newAnnots addObject:annot_from_your_main_array];
}
Comparing with the map view's annotations array will only work if the annotation objects in your main array are the actual annotations you give to the map view in addAnnotation: or addAnnotations:. Also, when your main array is "updated", it should only add the new annotations instead of rebuilding the whole array from scratch. If it does, the annotation references won't match with the ones in the map view's array.
The same applies if you are removing annotations on an update. The removed annotations could be added to a temporary "remove" list (by checking if annotations in the map view's array exist in your array) and passed to removeAnnotations:.
Note that if you update an existing annotation's coordinates in your main array, the map view will automatically update the pin's location as long as the annotation object in your array implements the setCoordinate: method.