I am not able to see the Blue current location dot when I use custom annotations
- (MKAnnotationView *) mapView:(MKMapView *) mapView viewForAnnotation:(id<MKAnnotation> ) annotation {
MKAnnotationView *customAnnotationView=[[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil] autorelease];
UIImage *pinImage = [UIImage imageNamed:#"ann.png"];
[customAnnotationView setImage:pinImage];
customAnnotationView.canShowCallout = YES;
//UIImageView *leftIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"ann.png"]];
//customAnnotationView.leftCalloutAccessoryView = leftIconView;
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self action:#selector(showDetails:) forControlEvents:UIControlEventTouchUpInside];
customAnnotationView.rightCalloutAccessoryView = rightButton;
return customAnnotationView;
}
if (annotation == map.userLocation) {
return nil;
}
Add this.:d
I got the answer now. Just need to add the following lines to the above code at the end just before return customAnnotationView;
if (annotation ==
mapView.userLocation) {
NSLog(#"nil"); return nil; }
thanks :)
The visibility of the current user location "blue dot" is unrelated to custom annotations. To make the user's current location show, you need to set the showsUserLocation property of your MKMapView to YES. For example:
yourMapView.showsUserLocation = YES;
or:
[yourMapView showsUserLocation] = YES;
Understand that there is a quirk in the way MapKit displays the current user location: in the simulator the UserLocation will always be Apple's headquarters in Cupertino, CA, USA. It will work fine on the device, however.
Edited to add:
As Terente points out, you do have to be careful not to "eat" the user's location annotation, and so must test to see if the annotation you're processing is the user's location. I wrap the logic with:
if ([annotation isKindOfClass:[MapLocation class]]) {
}
Where MapLocation is my annotation class.
Related
I am trying and trying to make my Entity move towards some previously described destination.
The entity moves on a microlevel over and over again but never reaches its destination. DestinationSystem checks with its update function if the Entity is close enough so it can choose a new destination for it.
I kindly ask you for help as I am absolutely out of ideas.
Here is my DestinationSystem's update function.
This system will only chose the current destination for the entity and then checks if the entity reached it.
func update(context: SceneUpdateContext) {
let walkers = context.scene.performQuery(Self.query)
walkers.forEach({ entity in
guard var walker = entity.components[DestinationComponent.self] as? DestinationComponent,
let _ = entity.components[MotionComponent.self] as? MotionComponent else { return }
defer {
entity.components[DestinationComponent.self] = walker
}
// set the default destination to 0
var distanceFromDestination: Float = 0
// check if walker component for this specific entity has any destination
if let destination = walker.destination {
// distract distance from it
distanceFromDestination = entity.distance(from: destination)
}
// check if the distance still is. If its tiny, then lets choose another distance
if distanceFromDestination < 0.02 {
var fixedDestination = SIMD3<Float>.spawnPoint(from: entity.transform.translation, radius: 0.7)
fixedDestination.y = Float(0)
// If there is any obstacle on the way to the destination, set that obstacle as the destination so it wont pass it, perhaps through the wall
let obstacles = context.scene.raycast(
from: entity.position,
to: fixedDestination,
query: .nearest,
mask: .sceneUnderstanding,
relativeTo: nil
)
if let nearest = obstacles.first {
fixedDestination = nearest.position
fixedDestination.y = Float(0)
}
walker.destination = fixedDestination
}
})
}
Here is my MotionSystem. Constant variable s calculates current translation to cross and multiplies it by the deltaTime of the context and 0.03 which I choose as a speed.
func update(context: SceneUpdateContext) {
context.scene.performQuery(Self.query).forEach { entity in
let fixedDelta: Float = Float(context.deltaTime)
guard let _ = entity.components[MotionComponent.self] as? MotionComponent,
let walker = entity.components[DestinationComponent.self] as? DestinationComponent
else { return }
var newTransform = entity.transform
let s = (walker.destination! - entity.transform.translation) * 0.03 * fixedDelta
newTransform.translation = s
newTransform.translation.y = Float(0)
entity.move(to: newTransform, relativeTo: entity.parent)
}
}
I believe it should take my Entity frame by frame to the destination point, then choose another one. It never will again.
Unless my math is terribly off?
Thank you for any help.
According to this scenario.
Used to test it using sample message - text. And it works fine.
I should implement that by using buttons (callbacks).
The real problem is :
Sample text :
context.Activity.Id
"mid.$cAAOmNGtaSJ9i1_f223cprKylFOpb"
on button click (callback) :
context.Activity.Id
"9Yw5TAcq1qr"
This is the code i used to post human support button :
msg.AttachmentLayout = AttachmentLayoutTypes.Carousel;
msg.Attachments = new List<Attachment>();
ThumbnailCard thumbnailCard2 = new ThumbnailCard()
{
Buttons = new List<CardAction>
{
new CardAction ()
{
Value = "Method_Support",
Type = "postBack",
Title = "Human Support"
},
},
};
msg.Attachments.Add(thumbnailCard2.ToAttachment());
await context.PostAsync(msg);
It returns activity.Id : 9Yw5TAcq1qr - as i already mentioned. I can't use that id to query Facebook graph api.
What's the best way to handle scenario like this ?
Is it possible to render all incoming messages as native Facebook (sample-text) messages ?
Is it possible to make call to graph api using callback's activity.id ?
Following my previous answer about how to link the Activity from botFramework to the messages in Conversation in Facebook's Graph API, I had a look to your problem.
Analysis
From my point of view, there is a strange thing in this Activity.Id value because on Facebook's side, all messages have the same id format, even for callbacks.
Here is a capture of 2 messages (1st one is the latest one) from Facebook Graph API:
{
"data": [{
"messages": {
"data": [
{
"id": "m_mid.$cAAC3Jml0RcBi2JK3Clcp01uu8FFe",
"message": "Human support"
},
{
"id": "m_mid.$cAAC3Jml0RcBi2I5bXlcp0kScM7af",
"message": ""
}
]
},
"id": "t_mid.$..."
}]
}
Message with empty text is a ThumbnailCard with a CardAction inside (type = postback, Value = Method_HumanSupport)
Human support is what is sent on the click on the CardAction
What is surprising is that on the bot side, for those 2 messages we have the following values for Activity.Id:
For "id": "m_mid.$cAAC3Jml0RcBi2I5bXlcp0kScM7af" (my Thumbnail) => mid.$cAAC3Jml0RcBi2I5bXlcp0kScM7af, so it's matching
For "id": "m_mid.$cAAC3Jml0RcBi2JK3Clcp01uu8FFe" (the callback) => DWhE2C0VO79, no match at all
For information my ThumbnailCard is made like the OP said:
var msg = context.MakeMessage();
msg.AttachmentLayout = AttachmentLayoutTypes.Carousel;
msg.Attachments = new List<Attachment>();
msg.Text = "updates & support";
ThumbnailCard thumbnailCard2 = new ThumbnailCard()
{
Buttons = new List<CardAction>
{
new CardAction ()
{
Value = "Method_HumanSupport",
Type = "postBack",
Title = "Human support"
}
}
};
I will add a question on Bot Framework GitHub Project.
Edit: issue logged: https://github.com/Microsoft/BotBuilder/issues/2950
Workaround
There are several workaround that will depend on your global use cases: you could try to log the Activity.Id of a "normal" message in the discussion and use this value later when your callback is clicked, or you can also try to change your flow to avoid making this kind of link between Bot Framework and Facebook Graph API.
I have an array of country names and wish to place them on a MKMapView as Placemarks. So for example if France is in the countryName array I would like a pin placed on the center of France.
Is there a way of doing this without having the lat/long stored for each country?
I would like to make this work offline and only require the map in its most basic and fully zoomed out image of the world.
I believe MKMapView holds some basic geo information so is the above possible without the use of GLGeocoder and a internet connection?
try this function for get latitude and longitude for address:-(if you use only country name then we get center lat nag long for that country)
-(CLLocationCoordinate2D) getLocationFromAddressString:(NSString*) countryStr {
NSString *urlAddressStr = [NSString stringWithFormat:#"http://maps.google.com/maps/geo?q=%#&output=csv",
[countryStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *locationStr = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlAddressStr]];
NSArray *items = [locationStr componentsSeparatedByString:#","];
double lat = 0.0;
double long = 0.0;
if([items count] >= 4 && [[items objectAtIndex:0] isEqualToString:#"200"])
{
lat = [[items objectAtIndex:2] doubleValue];
long = [[items objectAtIndex:3] doubleValue];
}
CLLocationCoordinate2D location;
location.latitude = lat;
location.longitude = long;
return location;
}
after you get latitude and longitude
1)add use the mapKit Framework
3)set latitude and longitude on region
3) use this function
- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id )annotation
This method will not work unless you store the data file (sqlite) into the application and query the database as you place the pins into the map. But it will guarantee the map data availability in offline mode.
Basically you can make use of the shape file available
http://thematicmapping.org/downloads/world_borders.php
Import it as sqlite file using the .loadshp command described
http://www.gaia-gis.it/gaia-sins/spatialite-tutorial-2.3.1.html
Once you have imported the sqlite file, you can just query something like
select lon,lat from world_borders where name like 'Zambia';
where
lon = longitude,
lat = latitude,
world_borders = table name
and 'Zambia' = country name.
Is it possible to read or write to plist when the application is in background state?
It is not possible to read your plist when your application is in the background, because your application is not running more than 10 minutes in the background state. There are only three options for keeping your application running more than 10 minutes in the background.
If you want to read and write your plist, do this when your application comes to the foreground state. For this you can read and write your plist in the application became active delegate method.
try this one..
- (void)readPlist
{
NSString *filePath = #"/System/Library/CoreServices/SystemVersion.plist";
NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
NSString *value;
value = [plistDict objectForKey:#"ProductVersion"];
/* You could now call the string "value" from somewhere to return the value of the string in the .plist specified, for the specified key. */
}
- (void)writeToPlist
{
NSString *filePath = #"/System/Library/CoreServices/SystemVersion.plist";
NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
[plistDict setValue:#"1.1.1" forKey:#"ProductVersion"];
[plistDict writeToFile:filePath atomically: YES];
/* This would change the firmware version in the plist to 1.1.1 by initing the NSDictionary with the plist, then changing the value of the string in the key "ProductVersion" to what you specified */
}
Hope this helps you!
i want the solution of below question, i dont know how to store sinup information in Plist, can any one knows please help.
Thanks in advance
Use Dummy data but the dummy data must not be in the code ,it should either be in an external file (plist/xml) or in a separate constant file.This improves the code management.
All screens must comply to Portrait and Landscape View Mode
1. The App will begin with the Login Screen, The screen should be having same functionality as any website.
a. Login
b. Sign Up
c. Maximum Tries (3) then lock the app
d. Requires Answer to secret question to unlock which will be accepted in sign up
If you are looking for storing small data like user credentials look for NSUserDefault.
For automatic login, if the user has logged in previously look this.
You can create a new .plist file to store the information.
Add New File in your project, of type "Property list". Its under the "Resource tab", on "Mac OS X" in the left pane of your xcode.
Once created, Now add new items in to it. The "Key" will be used the retrieve the value through the coding.
To retrieve the values in the coding, from .plist file, you can use this code:
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
NSDictionary* defaultSettings = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"YOUR_PLIST_FILE_NAME.plist" ofType:nil]];
[defaults registerDefaults:defaultSettings];
NSString *sName = [defaultSettings objectForKey:#"Name"]; //the Name is the Key in .plist file, so its corresponding value will be fetched and store in sName variable
NSString *defaultDomain = [defaultSettings objectForKey:#"domain"];
I hope it helps :)