This is the function I use to get the tile id for a given layer and a point in screen. It keeps in mind device scale factor.
- (int) getTileGIDMap:(CCTMXTiledMap *) map atLayer:(NSString *) layer andPosition:(CGPoint) position {
int GID = 0;
CCTMXLayer *mapLayer1 = [map layerNamed:layer];
int mapX = position.x * CC_CONTENT_SCALE_FACTOR() / (mapLayer1.mapTileSize.width);
int mapY = mapLayer1.layerSize.height - (position.y - map.position.y) * CC_CONTENT_SCALE_FACTOR() / mapLayer1.mapTileSize.height;
if (mapX >= 0 && mapY >= 0 && mapY < map.mapSize.height) {
GID = [mapLayer1 tileGIDAt:ccp(mapX, mapY)];
}
return GID;
}
Hope it helps